Hi SDL guys,
I have some code which toggles windowed <-> full screen and usually
works in Linux, Mac and Windows. It’s as follows :
void SDLVideoDriver::toggleFullScreen (void)
{
bool bWasFullScreen = getFullScreen();
int nOldFlags = m_pScreenSurf->flags;
int nOldW = m_pScreenSurf->w;
int nOldH = m_pScreenSurf->h;
SDL_Surface* pNewSurf = SDL_SetVideoMode(m_pScreenSurf->w,
m_pScreenSurf->h, 0, m_pScreenSurf->flags ^ SDL_FULLSCREEN);
if (!pNewSurf)
{
GameApp::writeToLog(String::fromFormat("S: Toggle failed (%d)
[%s]\n", bWasFullScreen, SDL_GetError()));
pNewSurf = SDL_SetVideoMode(nOldW, nOldH, 0, nOldFlags);
if (!pNewSurf)
GFC_FATAL(String::fromFormat("S: Couldn't restore old video
mode, aborting [%s]", SDL_GetError()));
}
[...more stuff follows...]
}
As you can see, it tries to toggle, and if the toggle fails, it tries to
restore the old video mode.
The problem is that, while it usually works, sometimes it doesn’t - and
the error messages I get are
S: Toggle failed (0) [DirectDraw2::SetCooperativeLevel: Exclusive mode
was already set]
and when it tries to restore the old video mode,
S: Couldn't restore old video mode, aborting
[DirectDraw2::CreateSurface(PRIMARY): Not in exclusive access mode]
So I can’t go from windowed to full screen because “exclusive mode is
already set”, and I can’t recreate the window because it says “not in
exclusive access mode”.
I’m not very knowledgeable in DirectDraw; does anyone know what this
means, and more importantly, how should I deal with it? What do you do
if toggling the video mode fails?
Thanks,
–Gabriel