Skip to content

Fix crash that happens when using SDL2's assert facilities #15

@i8degrees

Description

@i8degrees

To reproduce the bug:

Setup a non-fatal assertion that will always fail anywhere before the game
loop's event handling code is ran, such as in the initialization section of
an engine example. The NOM_ASSERT macro defaults to using SDL2's assert
facility.

// Note that this will be zero after ignoring the non-fatal assertion, but before 
// focusing the SDL window. We normally are expecting a value of one or greater; 
// it is an out of bounds because of this!)
NOM_DUMP(ev.key.window_id );

// Value should always be reported as one or greater.
NOM_DUMP(this->window[0].window_id() );

// First location of where the out of bounds err occurs
if ( this->window[ev.key.window_id - 1].window_id() == ev.key.window_id )
{
  // Second location of where the out of bounds err occurs
  this->window[ev.key.window_id - 1].toggle_fullscreen();
} // end window_id match

Workarounds:

Two options for averting the crash in the mean time: a) remember to focus the
window (by clicking on it) before using any of the code fragments that rely on
the a window_id value of one or greater; b) patching the code by checking for
out of bounds:

if( ( ev.key.window_id - 1 ) != MAXIMUM_WINDOWS-1 ) return;

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions