From c80f341711aff3fade2c61d3c45b73a543b2997d Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sun, 9 Oct 2016 19:17:58 -0500 Subject: [PATCH] Handle ERR_DROP during Com_GameRestart 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. --- code/qcommon/common.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/code/qcommon/common.c b/code/qcommon/common.c index 6d73a7bf..02ada762 100644 --- a/code/qcommon/common.c +++ b/code/qcommon/common.c @@ -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]; @@ -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); @@ -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(); @@ -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(); @@ -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( ); @@ -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); @@ -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; } }