[SDL] SDL_FreeSurface issue?
Lilith Calbridge
lilith at dcccd.edu
Sun Nov 12 17:19:22 PST 2006
As you've done it in your code, setting image to NULL after
deallocating, it should work okay. It would be nice to have
SDL_FreeSurface() return a NULL instead of a void to help eliminate the
step. That wouldn't eliminate the problem but it could lead to fewer
such errors.
I haven't used LoadIMG so I can't comment on that at the moment. Have
you tried replacing LoadIMG with SDL_LoadBMP()? Can you do any memory
availability tracking before and after the loads and frees?
--
Lilith
>>> On 11/12/2006 at 1:35 PM, in message
<loom.20061112T202743-266 at post.gmane.org>,
Armond <armond.sarkisian at gmail.com> wrote:
> Hi everyone,
>
> I want to know one thing. If I create a surface, allocate it and then
> deallocate it and then once more allocate it again, would that cause
a
> problem.
> I seem to have a problem with the examples below. I thought if you
> deallocate
> it, all should be well right?
>
> ////////////////////////////////////////
> image = LoadIMG( "ball.bmp" );
> if( !image ) // throw error
> SDL_FreeSurface( image );
> image = NULL; // just in case
> image = LoadIMG( "ball.bmp" );
> if( !image ) // throw error
> ////////////////////////////////////////
>
> Same for music. I seem to have a problem with this code if I load it
and
> unload
> it a few times in a row. The program halts and says "Not Responding."
It
> just
> freezes.
>
> ////////////////////////////////////////
> Mix_HaltMusic( );
> Mix_FreeMusic( my_sdl.music );
> my_sdl.music = Mix_LoadMUS( "music.wav" );
> if( !my_sdl.music ) // throw error
> if( Mix_PlayMusic( my_sdl.music, -1 ) == -1 ) // throw error
> ////////////////////////////////////////
>
> Also, is it a good idea to do this prior to freeing any surfaces?
>
> if( image != NULL ){ SDL_FreeSurface( image ); }
> if( music != NULL ){ Mix_FreeMusic( music ); }
>
> Just in case they are NULL, we woulden't want to free something that
is not
> there
>
> Any help would be appreciated.
>
> Thanks!
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
More information about the SDL
mailing list