]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Fix the +map crash once and for all. Defer stuffcmds until it's safe to run.
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 4 Jun 2020 12:11:20 +0000 (12:11 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 4 Jun 2020 12:11:20 +0000 (12:11 +0000)
Check if the literal quake.rc file exists rather than using stuffcmds as
an indicator of its existence, and use a new qboolean host_init to defer
stuffcmds.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12632 d7cf8633-e32d-0410-b094-e92efae38249

cmd.c
host.c

diff --git a/cmd.c b/cmd.c
index 4f13c0a9f578bcdb7f92623cbba3e3d136ad892d..d1820e2c7e748c03ba946f2dd7aab1b4d88724b9 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -397,6 +397,8 @@ void Cbuf_Frame(cmd_state_t *cmd)
 ==============================================================================
 */
 
+extern qboolean host_init;
+
 /*
 ===============
 Cmd_StuffCmds_f
@@ -413,6 +415,10 @@ static void Cmd_StuffCmds_f (cmd_state_t *cmd)
        // this is for all commandline options combined (and is bounds checked)
        char    build[MAX_INPUTLINE];
 
+       // come back later so we don't crash
+       if(host_init)
+               return;
+
        if (Cmd_Argc (cmd) != 1)
        {
                Con_Print("stuffcmds : execute command line parameters\n");
diff --git a/host.c b/host.c
index b4acbed650d36568a3a505c49083d44d884794ba..9a3d6ace0e82e46c5b88912b6933fc2be41d54d2 100644 (file)
--- a/host.c
+++ b/host.c
@@ -47,6 +47,9 @@ Memory is cleared / released when a server or client begins, not when they end.
 // how many frames have occurred
 // (checked by Host_Error and Host_SaveConfig_f)
 int host_framecount = 0;
+
+// Cloudwalk: set when Host_Init is executed
+qboolean host_init = false;
 // LadyHavoc: set when quit is executed
 qboolean host_shuttingdown = false;
 
@@ -328,6 +331,7 @@ static void Host_AddConfigText(cmd_state_t *cmd)
                Cbuf_InsertText(cmd, "alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec teu.rc\n");
        else
                Cbuf_InsertText(cmd, "alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec " STARTCONFIGFILENAME "\n");
+       Cbuf_Execute(cmd);
 }
 
 /*
@@ -1177,6 +1181,8 @@ static void Host_Init (void)
        qboolean dedicated_server = COM_CheckParm("-dedicated") || !cl_available;
        cmd_state_t *cmd = &cmd_client;
 
+       host_init = true;
+
        if (COM_CheckParm("-profilegameonly"))
                Sys_AllowProfiling(false);
 
@@ -1304,17 +1310,22 @@ static void Host_Init (void)
        }
 
        Host_AddConfigText(cmd);
-       Cbuf_Execute(cmd);
 
        Host_StartVideo();
 
-       // if stuffcmds wasn't run, then quake.rc is probably missing, use default
-       if (!host_stuffcmdsrun)
+       // if quake.rc is missing, use default
+       if (!FS_FileExists("quake.rc"))
        {
-               Cbuf_AddText(cmd, "exec default.cfg\nexec " CONFIGFILENAME "\nexec autoexec.cfg\nstuffcmds\n");
+               Cbuf_AddText(cmd, "exec default.cfg\nexec " CONFIGFILENAME "\nexec autoexec.cfg\n");
                Cbuf_Execute(cmd);
        }
 
+       host_init = false;
+
+       // run stuffcmds now, deferred previously because it can crash if a server starts that early
+       Cbuf_AddText(cmd,"stuffcmds\n");
+       Cbuf_Execute(cmd);
+
        Log_Start();
        
        // put up the loading image so the user doesn't stare at a black screen...