* Sys_Dialog for more user friendly error reporting

* (bug #3932) Recovery from bad video settings
This commit is contained in:
Tim Angus 2010-02-15 16:20:33 +00:00
parent 4876413217
commit 005f870ebe
13 changed files with 564 additions and 120 deletions

View file

@ -127,6 +127,60 @@ char *Sys_ConsoleInput(void)
return CON_Input( );
}
#ifdef DEDICATED
# define PID_FILENAME PRODUCT_NAME "_server.pid"
#else
# define PID_FILENAME PRODUCT_NAME ".pid"
#endif
/*
=================
Sys_PIDFileName
=================
*/
static char *Sys_PIDFileName( void )
{
return va( "%s/%s", Sys_TempPath( ), PID_FILENAME );
}
/*
=================
Sys_WritePIDFile
Return qtrue if there is an existing stale PID file
=================
*/
qboolean Sys_WritePIDFile( void )
{
char *pidFile = Sys_PIDFileName( );
FILE *f;
qboolean stale = qfalse;
// First, check if the pid file is already there
if( ( f = fopen( pidFile, "r" ) ) != NULL )
{
char pidBuffer[ 64 ] = { 0 };
int pid;
fread( pidBuffer, sizeof( char ), sizeof( pidBuffer ) - 1, f );
fclose( f );
pid = atoi( pidBuffer );
if( !Sys_PIDIsRunning( pid ) )
stale = qtrue;
}
if( ( f = fopen( pidFile, "w" ) ) != NULL )
{
fprintf( f, "%d", Sys_PID( ) );
fclose( f );
}
else
Com_Printf( S_COLOR_YELLOW "Couldn't write %s.\n", pidFile );
return stale;
}
/*
=================
Sys_Exit
@ -134,7 +188,7 @@ Sys_Exit
Single exit point (regular exit or in case of error)
=================
*/
void Sys_Exit( int ex )
static void Sys_Exit( int exitCode )
{
CON_Shutdown( );
@ -142,13 +196,13 @@ void Sys_Exit( int ex )
SDL_Quit( );
#endif
#ifdef NDEBUG
exit( ex );
#else
// Cause a backtrace on error exits
assert( ex == 0 );
exit( ex );
#endif
if( exitCode < 2 )
{
// Normal exit
remove( Sys_PIDFileName( ) );
}
exit( exitCode );
}
/*
@ -158,7 +212,6 @@ Sys_Quit
*/
void Sys_Quit( void )
{
CL_Shutdown( );
Sys_Exit( 0 );
}
@ -287,15 +340,14 @@ void Sys_Error( const char *error, ... )
va_list argptr;
char string[1024];
CL_Shutdown ();
va_start (argptr,error);
Q_vsnprintf (string, sizeof(string), error, argptr);
va_end (argptr);
CL_Shutdown( string );
Sys_ErrorDialog( string );
Sys_Exit( 1 );
Sys_Exit( 3 );
}
/*
@ -450,7 +502,7 @@ void Sys_ParseArgs( int argc, char **argv )
#else
fprintf( stdout, Q3_VERSION " client (%s)\n", date );
#endif
Sys_Exit(0);
Sys_Exit( 0 );
}
}
}
@ -480,14 +532,16 @@ void Sys_SigHandler( int signal )
else
{
signalcaught = qtrue;
fprintf( stderr, "Received signal %d, exiting...\n", signal );
#ifndef DEDICATED
CL_Shutdown();
CL_Shutdown( va( "Received signal %d", signal ) );
#endif
SV_Shutdown( "Signal caught" );
SV_Shutdown( va( "Received signal %d", signal ) );
}
Sys_Exit( 0 ); // Exit with 0 to avoid recursive signals
if( signal == SIGTERM || signal == SIGINT )
Sys_Exit( 1 );
else
Sys_Exit( 2 );
}
/*
@ -519,7 +573,10 @@ int main( int argc, char **argv )
if( SDL_VERSIONNUM( ver->major, ver->minor, ver->patch ) <
SDL_VERSIONNUM( MINSDL_MAJOR, MINSDL_MINOR, MINSDL_PATCH ) )
{
Sys_Print( "SDL version " MINSDL_VERSION " or greater required\n" );
Sys_Dialog( DT_ERROR, va( "SDL version " MINSDL_VERSION " or greater is required, "
"but only version %d.%d.%d was found. You may be able to obtain a more recent copy "
"from http://www.libsdl.org/.", ver->major, ver->minor, ver->patch ), "SDL Library Too Old" );
Sys_Exit( 1 );
}
#endif