Code not working in new thread

Login to reply to this topic.
Tue, 2008-07-01 14:27
Joined: 2008-07-01
Forum posts: 4

Hi all,
I have some code from the NokiaCV library which does not run in a new thread. Perhaps some of you have some hints on what could be the problems:

void CCameraMotion::UpdateMHI(CFbsBitmap *iCurFrame)
{
        iImageSize = iCurFrame->SizeInPixels();   

        /* Make it a 2bit image. */
        CNokiaCVImage* tmp = CNokiaCVImage::NewL();
        CleanupStack::PushL(tmp);
        tmp->CreateL(iImageSize, EGray2);
       
        // Every row is aligned so let's get the bytes right.
        const TInt bwBytes = 4 * (iImageSize.iWidth / 32 + (iImageSize.iWidth % 32 ? 1 : 0));
        TUint8* tmpPtr = reinterpret_cast<TUint8*>(tmp->Bitmap()->DataAddress());
        for(TInt y = 0; y < iImageSize.iHeight; y++)
                {
                for(TInt x = 0; x < iImageSize.iWidth; x++)
                        {
                        TRgb color;
                        iCurFrame->GetPixel(color, TPoint(x, y));
                        const TUint8 bwMask = 1 << (x % 8); /* Bits in reverse order. */
                        if(color.Gray256() < 0x90) /* Make it black. */
                                {
                                *(tmpPtr + y * bwBytes + x / 8 ) &= ~bwMask;
                                }
                        else                       /* Make it white. */
                                {
                                *(tmpPtr + y * bwBytes + x / 8 ) |= bwMask;
                                }
                    }
            }

        /* Add a new image into MHI. */
        if(iMhi)
                {
                iMhi->AddImage(*tmp);
                iMhi->GetImage(*iMhiImage);
                }
        else
                {
                iMhi = CMotionHistoryImage::NewL(*tmp, 3);
                iMhiImage = CNokiaCVImage::NewL();
                iMhiImage->CreateL(iImageSize, EGray256);
                }

        CleanupStack::PopAndDestroy();
}

One thing that I found out was that the new thread needs a connection to the Font and Bitmap server. This can be done with the following command: User::LeaveIfError(RFbsSession::Connect());
With this it works until the second if-else-statement but the application gets stuck at the command iMhi->AddImage(*tmp).
Many thanks for your help
Marcel


Wed, 2008-07-02 08:27
Joined: 2005-04-13
Forum posts: 120
Re: Code not working in new thread

it seems you are using main process's heap which is somehow not accessible. You can try creating a threads own heap address space and then try executing the same code.


Jupitar

Wed, 2008-07-02 09:32
Joined: 2004-11-29
Forum posts: 1197
Re: Code not working in new thread

There is no such thing as the "main process's heap", all heaps are assigned to threads, and all memory is always shared between all threads in the same process. (That is after all the definition of what differs a thread from a process)

My question is, what is this "MHI" thing, and have you created and initialized it in the current (new) thread? (I'm not familiar with the NokiaCV example)

Maybe it too needs a connection to something, and then you have to create/connect it in the thread where you want to use it.

Wed, 2008-07-02 09:43
Joined: 2005-04-13
Forum posts: 120
Re: Code not working in new thread

yes alh you are right. I think i mexed client-server & thread concepts toghether. sorry for the confusion created.


Jupitar

Thu, 2008-07-03 16:50
Joined: 2008-07-01
Forum posts: 4
Re: Code not working in new thread

Hi,
thanks for your replies.
I solved the problem by defining the iMhi and iMhiImage as local method variables and letting the UpdateMhi() function run forever. It is then controlled by the Rthread.Suspend and Rthread.Resume functions.
Greetings
Marcel

  • Login to reply to this topic.