Skip to content

Commit

Permalink
- fix wrong init handling of cvars caught in test
Browse files Browse the repository at this point in the history
  • Loading branch information
kaffeewolf committed Dec 7, 2024
1 parent 0d524ac commit d35e12a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion code/foundation/core/cvar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ CVar*
CVarCreate(CVarCreateInfo const& info)
{
CVar* ptr = CVarGet(info.name);
const bool needsInit = (ptr == nullptr);
if (ptr == nullptr)
{
IndexT varIndex = cVarOffset++;
n_assert(varIndex < MAX_CVARS);
ptr = &cVars[varIndex];
cVarTable.Add(info.name, varIndex);
CVarParseWrite(ptr, info.defaultValue);
}
n_assert2(!Util::String(info.name).ContainsCharFromSet(" "), "CVar name cannot contain spaces.");

Expand All @@ -57,6 +57,10 @@ CVarCreate(CVarCreateInfo const& info)
{
ptr->description = info.description;
}
if (needsInit)
{
CVarParseWrite(ptr, info.defaultValue);
}
return ptr;
}

Expand Down

0 comments on commit d35e12a

Please sign in to comment.