[SDL] Semantics of SDL_SetVideoMode and the surface it returns

Brian brian.ripoff at gmail.com
Tue Oct 16 03:32:43 PDT 2007


The SDL_Surface returned by SDL_SetVideoMode is special.

To quote the SDL wiki
(http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetVideoMode):

The surface returned is freed by SDL_Quit and should not be freed by
the caller. Note: This rule includes consecutive calls to
SDL_SetVideoMode (i.e. resize or resolution change) - the pre-existing
surface will be released automatically.

On 16/10/2007, Solra Bizna <sbizna at tejat.net> wrote:
> I'm writing an SDL binding. (Thanks to a helpful investigator
> off-list, I got an answer to my previous question.) I'm worried about
> the semantics of the surface SDL_SetVideoMode returns. Is it safe to
> SDL_FreeSurface it? When SDL_SetVideoMode is called again, is it safe
> to SDL_FreeSurface the *old* display surface? Is the old display
> surface even still valid?
> I need to know because the language the binding is for has garbage
> collection, and I'm trying to strip explicit memory allocation and
> deallocation from my binding. I need to know whether I need to somehow
> fence the SDL_Surface garbage collection method to avoid the display
> surface, and whether to flag the old display surface as invalid
> whenever the video mode is reset.


More information about the SDL mailing list