[SDL] SDL_TTF locks while trying to free surface
kos at climaxgroup.com
Tue Mar 8 03:15:20 PST 2005
I've got a simple font renderer based on the glFont example
that comes with SDL_TTF...
Occasionaly (I'd say about 10% repro rate) I get a lock-up
and from the callstack it seems it's either happening
when calling glTexImage2D or when calling SDL_FreeSurface.
Here's some code that should help (it's simplified so that its
more to the point):
// INIT CODE HAPPENS ONCE
glGenTextures(1, &mTexture); // create once, re-use for all font rendering
mFont = TTF_OpenFont(blah, blah);
// RENDER TEXT CODE HAPPENS OVER AND OVER AGAIN
// (e.g for debug text, it happens every tick)
mTextSurface = TTF_RenderText_Method(blah, blah, blah);
image = SDL_CreateRGBSurface(...);
// save alpha blending attrib goes here
SDL_BlitSurface(mTextSurface, flag, alpha);
// restore alpha blending here
//glTexParameteri stuff goes here
SDL_FreeSurface(image); // **BOOM...callstack pointer here (so it maybe the
glTexImage2D that is causing the problems
Normally the code carries on with
Enter2DMode(); // goes into glOrtho etc.
// render with glTexCoord2f and glVertex2i
Exit2DMode(); // goes back to normal
SDL_FreeSurface(mTextSurface); // free this every tick after
TTF_RenderText_Method has done it's work...
// CLEANUP code HAPPENS ONCE after we're all done (i.e. when app is about to
More information about the SDL