This explicitly deregisters CSQC commands every time CSQC shuts down. This patch
also avoids Z_Malloc'ing the cmd names for each CSQC command and avoids forcing
a Cmd_AddCommand if the command exists.
CSQC was force-adding a command even if it already existed, and when it did,
it would pass a pointer from a mempool that would later get freed when
CSQC shuts down, and Windows' strcasecmp doesn't like dangling pointers.
The Z_Malloc wasn't much better because it could have caused a memory leak.
So the best solution was to only pass the pointer but make sure the commands
are freed when CSQC shuts down.
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12558
d7cf8633-e32d-0410-b094-
e92efae38249
//#352 void(string cmdname) registercommand (EXT_CSQC)
static void VM_CL_registercmd (prvm_prog_t *prog)
{
- char *t;
VM_SAFEPARMCOUNT(1, VM_CL_registercmd);
if(!Cmd_Exists(&cmd_client, PRVM_G_STRING(OFS_PARM0)))
- {
- size_t alloclen;
-
- alloclen = strlen(PRVM_G_STRING(OFS_PARM0)) + 1;
- t = (char *)Z_Malloc(alloclen);
- memcpy(t, PRVM_G_STRING(OFS_PARM0), alloclen);
- Cmd_AddCommand(&cmd_client, t, NULL, "console command created by QuakeC");
- }
- else
Cmd_AddCommand(&cmd_client, PRVM_G_STRING(OFS_PARM0), NULL, "console command created by QuakeC");
-
}
//#360 float() readbyte (EXT_CSQC)
return buf;
}
-void Cmd_ClearCsqcFuncs (cmd_state_t *cmd)
+// TODO: Make this more generic?
+void Cmd_ClearCSQCCommands (cmd_state_t *cmd)
{
cmd_function_t *func;
- for (func = cmd->userdefined->csqc_functions; func; func = func->next)
- func->csqcfunc = false;
+ cmd_function_t **next = &cmd->userdefined->csqc_functions;
+
+ while(*next)
+ {
+ func = *next;
+ *next = func->next;
+ Z_Free(func);
+ }
}
/*
/// enclosing quote marks are also put.
qboolean Cmd_QuoteString(char *out, size_t outlen, const char *in, const char *quoteset, qboolean putquotes);
-void Cmd_ClearCsqcFuncs (cmd_state_t *cmd);
+void Cmd_ClearCSQCCommands (cmd_state_t *cmd);
#endif
void CL_VM_ShutDown (void)
{
prvm_prog_t *prog = CLVM_prog;
- Cmd_ClearCsqcFuncs(&cmd_client);
+ Cmd_ClearCSQCCommands(&cmd_client);
//Cvar_SetValueQuick(&csqc_progcrc, -1);
//Cvar_SetValueQuick(&csqc_progsize, -1);
if(!cl.csqc_loaded)
void Sbar_Init (void)
{
- Cmd_AddCommand(&cmd_client, "+showscores", Sbar_ShowScores_f, "show scoreboard");
- Cmd_AddCommand(&cmd_client, "-showscores", Sbar_DontShowScores_f, "hide scoreboard");
+ if(gamemode == GAME_NORMAL) // Workaround so Quake doesn't trample on Xonotic.
+ {
+ Cmd_AddCommand(&cmd_client, "+showscores", Sbar_ShowScores_f, "show scoreboard");
+ Cmd_AddCommand(&cmd_client, "-showscores", Sbar_DontShowScores_f, "hide scoreboard");
+ }
Cvar_RegisterVariable(&showfps);
Cvar_RegisterVariable(&showsound);
Cvar_RegisterVariable(&showblur);