SDL Semaphores OR How Rachel Debugs Code

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Moosader
Game Developer
Game Developer
Posts: 1081
Joined: Wed May 07, 2008 12:29 am
Current Project: Find out at: http://www.youtube.com/coderrach
Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
Programming Language of Choice: C++
Location: Kansas City
Contact:

SDL Semaphores OR How Rachel Debugs Code

Post 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
Post Reply