Changing SDL_WINDOWID environment

I’m currently using the SDL_WINDOWID variable to embed video in a GTK
widget. The problem is I’d like to be able to change it and to unset it
and re-init the video subsytem. The problem is that the application
crashes with this message when I try to re-init the subsystem:

Gdk-ERROR **: BadShmSeg (invalid shared segment parameter)
serial 15 error_code 170 request_code 146 minor_code 2

Re-Initting the whole thing causes even more disastrous problems.
One huge gotcha to this is that smpeg or avifile are open and have a file
playing, but I try to stop and to the best of my ability make sure that
the libraries don’t try to do anything until the QuitSubsystem and
InitSubsystem have completed. Here is the code that I’ve been trying to
use for the case of simply yanking out the Window:


Is this the fault of SDL or of avifile/smpeg? For smpeg I try to set the
surface to None before trying this, doing this, then creating a new
screen and doing SMPEG_setdisplay again. Is this just a hopeless cause?