From 452eb5a83d85db2d0c38215472fde386f8696aff Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 9 Jul 2019 20:16:08 +0900 Subject: [PATCH] Preserve parsed cvar values when string is same Fixes parsed developer flags on the command line getting reset. --- libs/util/cvar.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/libs/util/cvar.c b/libs/util/cvar.c index 3b30b00f9..e3e14236f 100644 --- a/libs/util/cvar.c +++ b/libs/util/cvar.c @@ -264,19 +264,21 @@ Cvar_Set (cvar_t *var, const char *value) } changed = !strequal (var->string, value); - free ((char*)var->string); // free the old value string + if (changed) { + free ((char*)var->string); // free the old value string - var->string = strdup (value); - var->value = atof (var->string); - var->int_val = atoi (var->string); - VectorZero (var->vec); - vals = sscanf (var->string, "%f %f %f", - &var->vec[0], &var->vec[1], &var->vec[2]); - if (vals == 1) - var->vec[2] = var->vec[1] = var->vec[0]; + var->string = strdup (value); + var->value = atof (var->string); + var->int_val = atoi (var->string); + VectorZero (var->vec); + vals = sscanf (var->string, "%f %f %f", + &var->vec[0], &var->vec[1], &var->vec[2]); + if (vals == 1) + var->vec[2] = var->vec[1] = var->vec[0]; - if (changed && var->callback) - var->callback (var); + if (var->callback) + var->callback (var); + } } VISIBLE void