From 8d089a11fab3b4310b442f17e5f280e2c2159390 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 4 Nov 2019 23:11:10 +0100 Subject: [PATCH] - for initializing tab commands a separate static lookup function must be used to get the button names. Because order of initialization for static objects is undefined. --- source/common/console/c_buttons.cpp | 9 +++++++++ source/common/console/c_dispatch.cpp | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/source/common/console/c_buttons.cpp b/source/common/console/c_buttons.cpp index 0badf8309..9bc845e40 100644 --- a/source/common/console/c_buttons.cpp +++ b/source/common/console/c_buttons.cpp @@ -128,6 +128,15 @@ static const ButtonDesc gamefuncs[] = { }; +// This is for use by the tab command builder which can run before the optimized tables are initialized. +const char* StaticGetButtonName(int32_t func) +{ + for (auto& entry : gamefuncs) + if (entry.index == func) return entry.name; + return ""; +} + + //============================================================================= // diff --git a/source/common/console/c_dispatch.cpp b/source/common/console/c_dispatch.cpp index feebae09e..8e01d12c0 100644 --- a/source/common/console/c_dispatch.cpp +++ b/source/common/console/c_dispatch.cpp @@ -432,6 +432,8 @@ FConsoleCommand* FConsoleCommand::FindByName (const char* name) return FindNameInHashTable (Commands, name, strlen (name)); } +const char* StaticGetButtonName(int32_t func); + FConsoleCommand::FConsoleCommand (const char *name, CCmdRun runFunc) : m_RunFunc (runFunc) { @@ -446,7 +448,7 @@ FConsoleCommand::FConsoleCommand (const char *name, CCmdRun runFunc) // Add all the action commands for tab completion for (i = 0; i < buttonMap.NumButtons(); i++) { - FString tname = "+"; tname << buttonMap.GetButtonName(i); + FString tname = "+"; tname << StaticGetButtonName(i); C_AddTabCommand (tname); tname.Substitute('+', '-'); C_AddTabCommand (tname);