PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Can´t draw in the thread??

Hi!!

I´m creating a thread class and I passed the backbuffer from the processNextFrame to the thread class to draw something. However I couldn´t see the text I want to print on the screen. Here is my code:


//////// FUNCTION IN THE THREAD CLASS ////
void ThreadClass::SetGapiSurface(CGapiSurface* backbuff){
//backbuff from the ProcessNextFrame
pbackbuff = backbuff;

}

DWORD WINAPI ThreadClass::ThreadFunction(){

while(m_threadstarted)
{

TCHAR* msg= _T("CANT PRINT THIS OUT");

pbackbuff(->DrawText(120, 280, msg,psystemfont, GDDRAWTEXT_CENTER, NULL, 0, NULL);


}

}
/////////// END ////////////


Does this whileloop affect the processNextFrame??
anyway to clue this out?? thxz
Whoa, be careful here. The CGapiSurface class is not guaranteed to be thread-safe. You are basically accessing a shared variable from two different places. Since you have no control of the scheduler and how it allows different threads to run, you can be almost certain that weird behavior, like this, will pop up.

Try protecting access to the CGapiSurface with a critical section. This probably won't do wonders for your framerate (and will most likely eliminate the performance you were hoping to gain by using several threads), but at least you will be able to tell if something is drawn or not.

If you are not accessing the backbuffer anywhere but here, I regret to say that I cannot see why your code shouldn't work.