Broken assert/MessageBox after calling SDL

Hi,

I’ve searched for an answer about this on the mailing list archives and on
Google but can’t find an answer. However, I find people with the same
problem than me. A similar issues was reported to this mailing list but it
was left unanswered:

http://www.libsdl.org/pipermail/sdl/2004-January/059074.html

So the problem is: after I call ‘SDL_SetVideoMode( mWidth, mHeight, 32,
SDL_OPENGL );’, the Win32 MessageBox call (that VC++ uses for asserts)
returns immediately with an ID_ABORT return value. In the context of
assertion, the assert code just ends up calling exit() to kill the process
because it can’t deal with that return value.

Here’s some code that shows my little test, I can build a repro app quickly
if you guys need it. I’m using VC7.1.

bool wfApp::init(void)
{
mInitOK = false;

if ( SDL_Init( SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_TIMER ) <

0 )
{
assert( 0 );
DebugPrintf(“SDL Error: %s\n”, SDL_GetError());
return false;
}

/// Set window title
char titleBuffer[kMaxChar] = {0};
_snprintf(titleBuffer, kMaxChar, "%s %i.%i", kAppTitle,

kAppMajorVersion, kAppMinorVersion);
SDL_WM_SetCaption( titleBuffer, NULL );

//////////////////////////////////////////////////////
// THIS ASSERT WORKS!
//////////////////////////////////////////////////////
assert( 0 );

/// Initialize output window
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ) ;
SDL_Surface* pMainSurf = SDL_SetVideoMode( mWidth, mHeight, 32,

SDL_OPENGL );
if( !pMainSurf )
{
assert( 0 );
DebugPrintf(“SDL Error: %s\n”, SDL_GetError());
return false;
}

//////////////////////////////////////////////////////
// THIS ASSERT KILLS THE PROGRAM!
//////////////////////////////////////////////////////
assert( 0 );

mInitOK = true;
return true;

}

It’s driving me nuts, all my asserts are not working. I’m a big assert
(ab)user.

Stephane

Sorry for the self-reply but I’m using SDL 1.2.9. I figure it might be
useful :)> -----Original Message-----

From: sdl-bounces+s=binarez.com at libsdl.org [mailto:sdl-
bounces+s=binarez.com at libsdl.org] On Behalf Of Stephane Duguay
Sent: Sunday, February 26, 2006 12:07 PM
To: sdl at libsdl.org
Subject: [SDL] Broken assert/MessageBox after calling SDL

Hi,

I’ve searched for an answer about this on the mailing list archives and on
Google but can’t find an answer. However, I find people with the same
problem than me. A similar issues was reported to this mailing list but it
was left unanswered:

http://www.libsdl.org/pipermail/sdl/2004-January/059074.html

So the problem is: after I call ‘SDL_SetVideoMode( mWidth, mHeight, 32,
SDL_OPENGL );’, the Win32 MessageBox call (that VC++ uses for asserts)
returns immediately with an ID_ABORT return value. In the context of
assertion, the assert code just ends up calling exit() to kill the process
because it can’t deal with that return value.

Here’s some code that shows my little test, I can build a repro app
quickly
if you guys need it. I’m using VC7.1.

bool wfApp::init(void)
{
mInitOK = false;

if ( SDL_Init( SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_TIMER ) <
0 )
{
assert( 0 );
DebugPrintf(“SDL Error: %s\n”, SDL_GetError());
return false;
}

/// Set window title
char titleBuffer[kMaxChar] = {0};
_snprintf(titleBuffer, kMaxChar, “%s %i.%i”, kAppTitle,
kAppMajorVersion, kAppMinorVersion);
SDL_WM_SetCaption( titleBuffer, NULL );

//////////////////////////////////////////////////////
// THIS ASSERT WORKS!
//////////////////////////////////////////////////////
assert( 0 );

/// Initialize output window
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ) ;
SDL_Surface* pMainSurf = SDL_SetVideoMode( mWidth, mHeight, 32,
SDL_OPENGL );
if( !pMainSurf )
{
assert( 0 );
DebugPrintf(“SDL Error: %s\n”, SDL_GetError());
return false;
}

//////////////////////////////////////////////////////
// THIS ASSERT KILLS THE PROGRAM!
//////////////////////////////////////////////////////
assert( 0 );

mInitOK = true;
return true;
}

It’s driving me nuts, all my asserts are not working. I’m a big assert
(ab)user.

Stephane


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi, I have the same problem. I never did step through the SDL code to
try to figure out what if anything inside of it might be suppressing
it. For all I know, my OpenGL driver hooks the message box to suppress
win32 message boxes under OpenGL. Anyhoo, I simply wrote my own assert
that does __asm { int 3; };

Not very nice, but I didn’t feel like spending all day trying to find
a solution.

Matthew> Hi,

I’ve searched for an answer about this on the mailing list archives and on
Google but can’t find an answer. However, I find people with the same
problem than me. A similar issues was reported to this mailing list but it
was left unanswered:

http://www.libsdl.org/pipermail/sdl/2004-January/059074.html

So the problem is: after I call ‘SDL_SetVideoMode( mWidth, mHeight, 32,
SDL_OPENGL );’, the Win32 MessageBox call (that VC++ uses for asserts)
returns immediately with an ID_ABORT return value. In the context of
assertion, the assert code just ends up calling exit() to kill the process
because it can’t deal with that return value.

Here’s some code that shows my little test, I can build a repro app quickly
if you guys need it. I’m using VC7.1.

bool wfApp::init(void)
{
mInitOK = false;

   if ( SDL_Init( SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_TIMER ) <

0 )
{
assert( 0 );
DebugPrintf(“SDL Error: %s\n”, SDL_GetError());
return false;
}

   /// Set window title
   char titleBuffer[kMaxChar] = {0};
   _snprintf(titleBuffer, kMaxChar, "%s %i.%i", kAppTitle,

kAppMajorVersion, kAppMinorVersion);
SDL_WM_SetCaption( titleBuffer, NULL );

   //////////////////////////////////////////////////////
   // THIS ASSERT WORKS!
   //////////////////////////////////////////////////////
   assert( 0 );

   /// Initialize output window
   SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ) ;
   SDL_Surface* pMainSurf = SDL_SetVideoMode( mWidth, mHeight, 32,

SDL_OPENGL );
if( !pMainSurf )
{
assert( 0 );
DebugPrintf(“SDL Error: %s\n”, SDL_GetError());
return false;
}

   //////////////////////////////////////////////////////
   // THIS ASSERT KILLS THE PROGRAM!
   //////////////////////////////////////////////////////
   assert( 0 );

   mInitOK = true;
   return true;

}

It’s driving me nuts, all my asserts are not working. I’m a big assert
(ab)user.

Yeah that would fix the problem for asserts but not with MessageBox which I
am using to display an error if my application fails to initialize properly.

Does anyone know why this is happening?

Thanks!
Stephane> -----Original Message-----

From: sdl-bounces+s=binarez.com at libsdl.org [mailto:sdl-
bounces+s=binarez.com at libsdl.org] On Behalf Of Matt J
Sent: Sunday, February 26, 2006 1:22 PM
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: Re: [SDL] Broken assert/MessageBox after calling SDL

Hi, I have the same problem. I never did step through the SDL code to
try to figure out what if anything inside of it might be suppressing
it. For all I know, my OpenGL driver hooks the message box to suppress
win32 message boxes under OpenGL. Anyhoo, I simply wrote my own assert
that does __asm { int 3; };

Not very nice, but I didn’t feel like spending all day trying to find
a solution.

Matthew

Hi,

I’ve searched for an answer about this on the mailing list archives and
on
Google but can’t find an answer. However, I find people with the same
problem than me. A similar issues was reported to this mailing list but
it
was left unanswered:

http://www.libsdl.org/pipermail/sdl/2004-January/059074.html

So the problem is: after I call ‘SDL_SetVideoMode( mWidth, mHeight, 32,
SDL_OPENGL );’, the Win32 MessageBox call (that VC++ uses for asserts)
returns immediately with an ID_ABORT return value. In the context of
assertion, the assert code just ends up calling exit() to kill the
process
because it can’t deal with that return value.

Here’s some code that shows my little test, I can build a repro app
quickly
if you guys need it. I’m using VC7.1.

bool wfApp::init(void)
{
mInitOK = false;

   if ( SDL_Init( SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_TIMER )

<

0 )
{
assert( 0 );
DebugPrintf(“SDL Error: %s\n”, SDL_GetError());
return false;
}

   /// Set window title
   char titleBuffer[kMaxChar] = {0};
   _snprintf(titleBuffer, kMaxChar, "%s %i.%i", kAppTitle,

kAppMajorVersion, kAppMinorVersion);
SDL_WM_SetCaption( titleBuffer, NULL );

   //////////////////////////////////////////////////////
   // THIS ASSERT WORKS!
   //////////////////////////////////////////////////////
   assert( 0 );

   /// Initialize output window
   SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ) ;
   SDL_Surface* pMainSurf = SDL_SetVideoMode( mWidth, mHeight, 32,

SDL_OPENGL );
if( !pMainSurf )
{
assert( 0 );
DebugPrintf(“SDL Error: %s\n”, SDL_GetError());
return false;
}

   //////////////////////////////////////////////////////
   // THIS ASSERT KILLS THE PROGRAM!
   //////////////////////////////////////////////////////
   assert( 0 );

   mInitOK = true;
   return true;

}

It’s driving me nuts, all my asserts are not working. I’m a big assert
(ab)user.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Stephane Duguay wrote:

the Win32 MessageBox call returns immediately

Your problem may be the same that I once had. See the
FlushMessageQueue() function and its calls in
http://cvs.sourceforge.net/viewcvs.py/pipmak/pipmak/source/pipmak_windows.c?view=markup
for how I solved it. Since you seem to be a Windows programmer, maybe
you can even explain to me what it does and why it works. :slight_smile:

-Christian

Hello Christian,

Monday, February 27, 2006, 9:08:08 AM, you wrote:

CW> Your problem may be the same that I once had. See the
CW> FlushMessageQueue() function and its calls in
CW> http://cvs.sourceforge.net/viewcvs.py/pipmak/pipmak/source/pipmak_windows.c?view=markup
CW> for how I solved it. Since you seem to be a Windows programmer, maybe
CW> you can even explain to me what it does and why it works. :slight_smile:

It’s a standard Win32 message handling loop. If you need this, you’re
not calling SDL_PumpEvents() when you should be, the message queue is
filling up, and this makes Win32 functions that open windows fail.–
Best regards,
Peter mailto:@Peter_Mulholland

Peter Mulholland wrote:

It’s a standard Win32 message handling loop. If you need this, you’re
not calling SDL_PumpEvents() when you should be, the message queue is
filling up, and this makes Win32 functions that open windows fail.

Hmm, that might be the case for the MessageBox, which is used shortly
after initializing SDL, when SDL_PumpEvents() hasn’t been called yet -
but the save/open dialogs are opened in response to user actions, so
SDL_PumpEvents() should have been called a few milliseconds earlier, at
most (and regularly every few ms, before that).

However, I don’t remember if I had the problem with both the
MessageBoxes and the save/open dialogs or just with one of them. It’s
possible that I just added the FlushMessageQueue() calls for good measure.

-Christian

That shouldn’t matter. The assert MessageBox is called with a MB_TASKMODAL
flag that will suspend the thread. It doesn’t matter if there is a message
loop or not.

Has you discovered a workaround (other than mine) or a way to get it working
as intended? If not, I’m going to experiment with my original hypothesis by
hooking the thread before and after assert is called. If the driver does
install a thread hook (I know SDL doesn’t, after checking the source), then
I should be able to disable it by not delegating to the other hooks . Of
course, that is dangerous magic right there. A messagebox seems to have a
unique class name so I can match it up that way in the hook proc.

Matthew> Peter Mulholland wrote:

It’s a standard Win32 message handling loop. If you need this, you’re
not calling SDL_PumpEvents() when you should be, the message queue is
filling up, and this makes Win32 functions that open windows fail.

Hmm, that might be the case for the MessageBox, which is used shortly
after initializing SDL, when SDL_PumpEvents() hasn’t been called yet -
but the save/open dialogs are opened in response to user actions, so
SDL_PumpEvents() should have been called a few milliseconds earlier, at
most (and regularly every few ms, before that).

However, I don’t remember if I had the problem with both the
MessageBoxes and the save/open dialogs or just with one of them. It’s
possible that I just added the FlushMessageQueue() calls for good measure.

-Christian


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Minor correction, it doesnt suspend the thread, it disables the top level
windows. Still, something must be forcing it to return IDABORT. That has a
value of 3.> –

That shouldn’t matter. The assert MessageBox is called with a
MB_TASKMODAL flag that will suspend the thread. It doesn’t matter if there
is a message loop or not.

Has you discovered a workaround (other than mine) or a way to get it
working as intended? If not, I’m going to experiment with my original
hypothesis by hooking the thread before and after assert is called. If the
driver does install a thread hook (I know SDL doesn’t, after checking the
source), then I should be able to disable it by not delegating to the other
hooks . Of course, that is dangerous magic right there. A messagebox seems
to have a unique class name so I can match it up that way in the hook proc.

Matthew

Peter Mulholland wrote:

It’s a standard Win32 message handling loop. If you need this, you’re
not calling SDL_PumpEvents() when you should be, the message queue is
filling up, and this makes Win32 functions that open windows fail.

Hmm, that might be the case for the MessageBox, which is used shortly
after initializing SDL, when SDL_PumpEvents() hasn’t been called yet -
but the save/open dialogs are opened in response to user actions, so
SDL_PumpEvents() should have been called a few milliseconds earlier, at
most (and regularly every few ms, before that).

However, I don’t remember if I had the problem with both the
MessageBoxes and the save/open dialogs or just with one of them. It’s
possible that I just added the FlushMessageQueue() calls for good
measure.

-Christian