Take the 2-minute tour ×

i'm using SDL1.2 to handle window-management in my openGL framework.

is it possible to destroy a window (surface) while the program is running without calling SDL_Quit()?

background: my framework is really just one gfx component (of potentially many such gfx components) in a multimedia environment. i cannot make any assumptions on what the other components are goind to do (e.g. whether they use SDL). i'm afraid that calling SDL_Quit() will have side-effects on the other components.

currently i'm doing something like:

SDL_Surface m_surface=0;

bool create_window() {
   int videoFlags = SDL_OPENGL;
   if(m_surface) {
       pritnf("window already made\n");
       return false;
   if(SDL_Init(SDL_INIT_VIDEO) < 0 ) {
       pritnf("unable to initialize SDLn");
       return false;
   m_surface = SDL_SetVideoMode(WIDTH, HEIGHT, BPP, videoFlags);


bool destroy_window() {
   if(m_surface) {

both create_window() and destroy_window() are supposed to get called multiple times during the life-cycle of the application. however, it feels weird to call SDL_Init() and SDL_Quit() multiple times.

btw, i'm using linux right now, but i'm targetting cross-platform (at least linux, osx, w32)

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I don't think this is possible with SDL 1.2, the screen surface has a special status and only SDL_Quit() can delete it. You can try using SDL_QuitSubSystem() to shutdown only the video part then SDL_InitSubSystem() to reinstate it, but I'm not sure it will work (I can't test this right now).

On the other hand, it looks easy to do with SDL 2.0 with SDL_CreateWindow() and SDL_DestroyWindow().

Either way, you would need to separate initialization (SDL_Init()) from window creation, and cleanup (SDL_Quit()) from window destruction.

share|improve this answer
thanks for the confirmation and the hints on the SubSystem init/quit. –  umläute Aug 21 '12 at 11:00
i am happy to remove SDL_Init()/SDL_Quit() from my window creation/destruction code; it's only there because this was the only way i could make it work for now; hopefully the subsystems will make that easier. –  umläute Aug 21 '12 at 11:01
as for SDL2, i would like to stick with the SDL-version that is comes with debian for now (which is unfortunately 1.2; there are (old) SDL1.3 packages available in the non-official "experimental" repositories, which afaiu is equivalent to SDL2) –  umläute Aug 21 '12 at 11:03
add comment

Your Answer


