From 695449b27b0210ce2cfba1446fdb458a908c7456 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Sun, 20 Dec 2020 18:55:23 +0000 Subject: [PATCH] cvar: Check if cvar is NULL before adding callback. Implement Cvar_Callback to fire off a callback at any time git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@13074 d7cf8633-e32d-0410-b094-e92efae38249 --- cvar.c | 20 ++++++++++++++++++-- cvar.h | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cvar.c b/cvar.c index 9b77bdab..f60a212e 100644 --- a/cvar.c +++ b/cvar.c @@ -365,6 +365,18 @@ void Cvar_UpdateAllAutoCvars(cvar_state_t *cvars) Cvar_UpdateAutoCvar(var); } +void Cvar_Callback(cvar_t *var) +{ + if (var == NULL) + { + Con_Print("Cvar_Callback: var == NULL\n"); + return; + } + + if(var->callback) + var->callback(var); +} + /* ============ Cvar_Set @@ -413,8 +425,7 @@ static void Cvar_SetQuick_Internal (cvar_t *var, const char *value) Cvar_UpdateAutoCvar(var); // Call the function stored in the cvar for bounds checking, cleanup, etc - if (var->callback) - var->callback(var); + Cvar_Callback(var); } void Cvar_SetQuick (cvar_t *var, const char *value) @@ -472,6 +483,11 @@ void Cvar_SetValue(cvar_state_t *cvars, const char *var_name, float value) void Cvar_RegisterCallback(cvar_t *variable, void (*callback)(cvar_t *)) { + if (variable == NULL) + { + Con_Print("Cvar_RegisterCallback: var == NULL\n"); + return; + } variable->callback = callback; } diff --git a/cvar.h b/cvar.h index e54e1817..18010dec 100644 --- a/cvar.h +++ b/cvar.h @@ -115,6 +115,8 @@ void Cvar_RegisterVariable(cvar_t *variable); qbool Cvar_Readonly (cvar_t *var, const char *cmd_name); +void Cvar_Callback(cvar_t *var); + /// equivelant to " " typed at the console void Cvar_Set (cvar_state_t *cvars, const char *var_name, const char *value); -- 2.39.2