engine: platform: sdl: check that we're handling SDL errors according to it's documentation

This commit is contained in:
Alibek Omarov 2023-10-26 23:06:50 +03:00
parent 34d7664342
commit 96a9172e36
2 changed files with 26 additions and 15 deletions

View File

@ -128,7 +128,7 @@ static qboolean SDLash_IsInstanceIDAGameController( SDL_JoystickID joyId )
return true;
return false;
#else
if( SDL_GameControllerFromInstanceID( joyId ) )
if( SDL_GameControllerFromInstanceID( joyId ) != NULL )
return true;
return false;
#endif
@ -148,7 +148,7 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
#else
int keynum = key.keysym.sym;
#endif
qboolean numLock = SDL_GetModState() & KMOD_NUM;
qboolean numLock = FBitSet( SDL_GetModState(), KMOD_NUM );
#if XASH_ANDROID
if( keynum == SDL_SCANCODE_VOLUMEUP || keynum == SDL_SCANCODE_VOLUMEDOWN )
@ -159,7 +159,7 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
if( SDL_IsTextInputActive() && down && cls.key_dest != key_game )
{
if( SDL_GetModState() & KMOD_CTRL )
if( FBitSet( SDL_GetModState(), KMOD_CTRL ))
{
if( keynum >= SDL_SCANCODE_A && keynum <= SDL_SCANCODE_Z )
{
@ -176,7 +176,7 @@ static void SDLash_KeyEvent( SDL_KeyboardEvent key )
if( isprint( keynum ) )
{
if( SDL_GetModState() & KMOD_SHIFT )
if( FBitSet( SDL_GetModState(), KMOD_SHIFT ))
{
keynum = Key_ToUpper( keynum );
}

View File

@ -158,8 +158,8 @@ void *SW_LockBuffer( void )
void *pixels;
int stride;
if( SDL_LockTexture(sw.tex, NULL, &pixels, &stride ) )
Sys_Error("%s", SDL_GetError());
if( SDL_LockTexture(sw.tex, NULL, &pixels, &stride ) < 0 )
Sys_Error( "%s: %s", __func__, SDL_GetError( ));
return pixels;
}
@ -272,7 +272,7 @@ static void R_InitVideoModes( void )
int j;
SDL_DisplayMode mode;
if( SDL_GetDisplayMode( displayIndex, i, &mode ) )
if( SDL_GetDisplayMode( displayIndex, i, &mode ) < 0 )
{
Msg( "SDL_GetDisplayMode: %s\n", SDL_GetError() );
continue;
@ -419,12 +419,16 @@ static qboolean WIN_SetWindowIcon( HICON ico )
{
SDL_SysWMinfo wminfo;
if( SDL_GetWindowWMInfo( host.hWnd, &wminfo ))
SDL_VERSION( &wminfo.version );
if( SDL_GetWindowWMInfo( host.hWnd, &wminfo ) == SDL_TRUE )
{
SendMessage( wminfo.info.win.window, WM_SETICON, ICON_SMALL, (LONG_PTR)ico );
SendMessage( wminfo.info.win.window, WM_SETICON, ICON_BIG, (LONG_PTR)ico );
return true;
}
Con_Reportf( S_ERROR "%s: %s", __func__, SDL_GetError( ));
return false;
}
#endif
@ -492,8 +496,8 @@ void GL_UpdateSwapInterval( void )
{
ClearBits( gl_vsync.flags, FCVAR_CHANGED );
if( SDL_GL_SetSwapInterval( gl_vsync.value ) )
Con_Reportf( S_ERROR "SDL_GL_SetSwapInterval: %s\n", SDL_GetError( ) );
if( SDL_GL_SetSwapInterval( gl_vsync.value ) < 0 )
Con_Reportf( S_ERROR "SDL_GL_SetSwapInterval: %s\n", SDL_GetError( ));
}
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
}
@ -542,7 +546,7 @@ GL_UpdateContext
static qboolean GL_UpdateContext( void )
{
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( SDL_GL_MakeCurrent( host.hWnd, glw_state.context ))
if( SDL_GL_MakeCurrent( host.hWnd, glw_state.context ) < 0 )
{
Con_Reportf( S_ERROR "GL_UpdateContext: %s\n", SDL_GetError());
return GL_DeleteContext();
@ -599,7 +603,7 @@ static qboolean VID_SetScreenResolution( int width, int height, window_mode_t wi
want.w = width;
want.h = height;
if( SDL_GetClosestDisplayMode( 0, &want, &got ) < 0 )
if( SDL_GetClosestDisplayMode( 0, &want, &got ) == NULL )
{
Con_Printf( S_ERROR "%s: SDL_GetClosestDisplayMode: %s", __func__, SDL_GetError( ));
return false;
@ -1047,7 +1051,7 @@ qboolean R_Init_Video( const int type )
// refdll can request some attributes
GL_SetupAttributes( );
if( SDL_GL_LoadLibrary( EGL_LIB ) )
if( SDL_GL_LoadLibrary( EGL_LIB ) < 0 )
{
Con_Reportf( S_ERROR "Couldn't initialize OpenGL: %s\n", SDL_GetError());
return false;
@ -1086,7 +1090,11 @@ rserr_t R_ChangeDisplaySettings( int width, int height, window_mode_t window_mod
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_DisplayMode displayMode;
SDL_GetCurrentDisplayMode( 0, &displayMode );
if( SDL_GetCurrentDisplayMode( 0, &displayMode ) < 0 )
{
Con_Printf( S_ERROR "SDL_GetCurrentDisplayMode: %s", SDL_GetError( ));
return rserr_invalid_mode;
}
// check our desktop attributes
refState.desktopBitsPixel = SDL_BITSPERPIXEL( displayMode.format );
@ -1115,8 +1123,11 @@ rserr_t R_ChangeDisplaySettings( int width, int height, window_mode_t window_mod
VID_RestoreScreenResolution();
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
if( SDL_SetWindowFullscreen( host.hWnd, 0 ))
if( SDL_SetWindowFullscreen( host.hWnd, 0 ) < 0 )
{
Con_Printf( S_ERROR "SDL_SetWindowFullscreen: %s", SDL_GetError( ));
return rserr_invalid_fullscreen;
}
#if SDL_VERSION_ATLEAST( 2, 0, 5 )
SDL_SetWindowResizable( host.hWnd, SDL_TRUE );
#endif