From 0ea49884162278c87e0a633692dcc39ebb5c6d73 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 24 Feb 2024 13:57:23 +0100 Subject: [PATCH] Tier1: fix crashes on some commands & fix assert The supplemental callback always seems to be linked to a nullsub, probably a debug only feature. Linked all registered concommands to this as well. --- src/tier1/convar.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/tier1/convar.cpp b/src/tier1/convar.cpp index b72f1617..6997e6a8 100644 --- a/src/tier1/convar.cpp +++ b/src/tier1/convar.cpp @@ -311,7 +311,7 @@ ConCommand::ConCommand(const char* pName, FnCommandCallbackV1_t callback, const int flags /*= 0*/, FnCommandCompletionCallback completionFunc /*= 0*/, const char* pszUsageString /*= 0*/) { m_fnSupplementalFinishCallBack = DefaultNullSub; - m_fnSupplementalCallback = nullptr; + m_fnSupplementalCallback = (FnCommandSupplementalCallback_t)DefaultNullSub; // Set the callback m_fnCommandCallbackV1 = callback; @@ -328,7 +328,7 @@ ConCommand::ConCommand(const char* pName, FnCommandCallback_t callback, const ch int flags /*= 0*/, FnCommandCompletionCallback completionFunc /*= 0*/, const char* pszUsageString /*= 0*/) { m_fnSupplementalFinishCallBack = DefaultNullSub; - m_fnSupplementalCallback = nullptr; + m_fnSupplementalCallback = (FnCommandSupplementalCallback_t)DefaultNullSub; // Set the callback m_fnCommandCallback = callback; @@ -345,7 +345,7 @@ ConCommand::ConCommand(const char* pName, ICommandCallback* pCallback, const cha int flags /*= 0*/, ICommandCompletionCallback* pCompletionCallback /*= 0*/, const char* pszUsageString /*= 0*/) { m_fnSupplementalFinishCallBack = DefaultNullSub; - m_fnSupplementalCallback = nullptr; + m_fnSupplementalCallback = (FnCommandSupplementalCallback_t)DefaultNullSub; // Set the callback m_pCommandCallback = pCallback; @@ -416,11 +416,16 @@ bool ConCommand::CanAutoComplete(void) const //----------------------------------------------------------------------------- void ConCommand::Dispatch(const ECommandTarget_t target, const CCommand& command, const bool bCallSupplemental) { + // If this is still false towards the end of this function, there is a bug + // somewhere in code + bool bRanCallback = false; + if (m_bUsingNewCommandCallback) { if (m_fnCommandCallback) { (*m_fnCommandCallback)(command); + bRanCallback = true; } } else if (m_bUsingCommandCallbackInterface) @@ -428,6 +433,7 @@ void ConCommand::Dispatch(const ECommandTarget_t target, const CCommand& command if (m_pCommandCallback) { m_pCommandCallback->CommandCallback(command); + bRanCallback = true; } } else @@ -435,6 +441,7 @@ void ConCommand::Dispatch(const ECommandTarget_t target, const CCommand& command if (m_fnCommandCallbackV1) { (*m_fnCommandCallbackV1)(); + bRanCallback = true; } } @@ -444,7 +451,7 @@ void ConCommand::Dispatch(const ECommandTarget_t target, const CCommand& command } // Command without callback!!! - AssertMsg(0, "Encountered ConCommand '%s' without a callback!\n", GetName()); + AssertMsg(bRanCallback, "Encountered ConCommand '%s' without a callback!\n", GetName()); } //-----------------------------------------------------------------------------