Skip to content

Commit

Permalink
Handle ERR_DROP during Com_GameRestart
Browse files Browse the repository at this point in the history
If ERR_DROP during Com_GameRestart after shutting down client, Com_Error
needs to restart the client otherwise there is just a black window. Also,
clear the game restarting flag in Com_Error otherwise it's not possible to
run Com_GameRestart again later.

I don't know of a way to trigger ERR_DROP, in FS_Restart for instance,
without engine changes however.
  • Loading branch information
zturtleman committed Oct 10, 2016
1 parent 978afd7 commit c80f341
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions code/qcommon/common.c
Expand Up @@ -115,6 +115,7 @@ int com_frameNumber;
qboolean com_errorEntered = qfalse;
qboolean com_fullyInitialized = qfalse;
qboolean com_gameRestarting = qfalse;
qboolean com_gameClientRestarting = qfalse;

char com_errorMessage[MAXPRINTMSG];

Expand Down Expand Up @@ -264,6 +265,7 @@ void QDECL Com_Error( int code, const char *fmt, ... ) {
static int lastErrorTime;
static int errorCount;
int currentTime;
qboolean restartClient;

if(com_errorEntered)
Sys_Error("recursive error after: %s", com_errorMessage);
Expand Down Expand Up @@ -296,9 +298,17 @@ void QDECL Com_Error( int code, const char *fmt, ... ) {
if (code != ERR_DISCONNECT && code != ERR_NEED_CD)
Cvar_Set("com_errorMessage", com_errorMessage);

restartClient = com_gameClientRestarting && !( com_cl_running && com_cl_running->integer );

com_gameRestarting = qfalse;
com_gameClientRestarting = qfalse;

if (code == ERR_DISCONNECT || code == ERR_SERVERDISCONNECT) {
VM_Forced_Unload_Start();
SV_Shutdown( "Server disconnected" );
if ( restartClient ) {
CL_Init();
}
CL_Disconnect( qtrue );
CL_FlushMemory( );
VM_Forced_Unload_Done();
Expand All @@ -310,6 +320,9 @@ void QDECL Com_Error( int code, const char *fmt, ... ) {
Com_Printf ("********************\nERROR: %s\n********************\n", com_errorMessage);
VM_Forced_Unload_Start();
SV_Shutdown (va("Server crashed: %s", com_errorMessage));
if ( restartClient ) {
CL_Init();
}
CL_Disconnect( qtrue );
CL_FlushMemory( );
VM_Forced_Unload_Done();
Expand All @@ -319,6 +332,9 @@ void QDECL Com_Error( int code, const char *fmt, ... ) {
} else if ( code == ERR_NEED_CD ) {
VM_Forced_Unload_Start();
SV_Shutdown( "Server didn't have CD" );
if ( restartClient ) {
CL_Init();
}
if ( com_cl_running && com_cl_running->integer ) {
CL_Disconnect( qtrue );
CL_FlushMemory( );
Expand Down Expand Up @@ -2362,16 +2378,14 @@ void Com_GameRestart(int checksumFeed, qboolean disconnect)
// make sure no recursion can be triggered
if(!com_gameRestarting && com_fullyInitialized)
{
int clWasRunning;

com_gameRestarting = qtrue;
clWasRunning = com_cl_running->integer;
com_gameClientRestarting = com_cl_running->integer;

// Kill server if we have one
if(com_sv_running->integer)
SV_Shutdown("Game directory changed");

if(clWasRunning)
if(com_gameClientRestarting)
{
if(disconnect)
CL_Disconnect(qfalse);
Expand All @@ -2393,13 +2407,14 @@ void Com_GameRestart(int checksumFeed, qboolean disconnect)
NET_Restart_f();
}

if(clWasRunning)
if(com_gameClientRestarting)
{
CL_Init();
CL_StartHunkUsers(qfalse);
}

com_gameRestarting = qfalse;
com_gameClientRestarting = qfalse;
}
}

Expand Down

0 comments on commit c80f341

Please sign in to comment.