Page 1 of 1

SDL Semaphores OR How Rachel Debugs Code

Posted: Sun Nov 02, 2008 5:12 pm
by Moosader
I'll extrapolate more on this later if anyone knows much about this stuff, but I keep trying to implement semaphores with my multithreading in Pickin Online Sicks, and I either keep getting segfaults (I have an array of surfaces, which are lines of text), or "Multiple definition of " something with the semaphore.

*note* Don't link me to lazyfoo. I'm already using his tutorial.

My stuff is like this:

void Output::Draw()
{
semaphore.Lock();
for ( int i=0; i<MAXOUTPUT; i++ )
{
//txtSurface = TTF_RenderText_Solid( font, line.str.c_str(), line.color );
txtSurface = NULL;
line.str = "";
line.color = colEVENT;
}
semaphore.Unlock();
}

where Lock() and Unlock() just call SDL_SemWait( sockLock ); and SDL_SemPost( sockLock );

The commented out section has a segfault from the very first iteration, but the three other lines are OK. (Just there to test out)

Another note is that if I have no semaphores or other protection from main and the thread messing with stuff, the server app runs fine. >_>;
So it's the lock causing the segfault, but I don't know how to "properly" use the lock, as it seems like I'm using it like lazyfoo says. :(

*edit* nevermind. It WAS working without semaphores, but now it's giving me the same error again. All I did was fix "state == LISTEN" to "state = LISTEN", then back again. More fucking segfaults with the font texturing thing! >_<

JESUS FUCKING CHRIST.


*edit*
Okay, this works, I added an extra surface to the class.
for ( int i=0; i<MAXOUTPUT; i++ )
{
txtSurface = ass;
}
It's totally okay with that. So it's not the surface like I thought.
Both the txtSurface and the line arrays are the same size, though. v_v

*edit*
I'm really confused. Using the TTF_RenderText_Solid function isn't working for me anymore. It's giving me the segfault, and I don't understand. T_T