SDL_TTF locks while trying to free surface

Hello all,

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

TTF_Init();
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
glBindTexture(2D, mTexture);
//glTexParameteri stuff goes here
glTexImage2D(stuff, image->pixels);

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
exit)
glDeleteTextures(1, &mTexture);
TTF_CloseFont(mFont);

Any ideas?
cheers,
K.

Hello all,

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

TTF_Init();
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
glBindTexture(2D, mTexture);
//glTexParameteri stuff goes here
glTexImage2D(stuff, image->pixels);
You should lock the image surface before accessing pixels,
SDL_LockSurface(iamge) then unlock afterwards:SDL_UnlockSurface(image)On Tue, 8 Mar 2005 11:15:20 -0000, Kostas Kostiadis wrote:

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
exit)
glDeleteTextures(1, &mTexture);
TTF_CloseFont(mFont);

Any ideas?
cheers,
K.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl