From b52054de1e88d77f20a625d55fb1b32b03109c24 Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Sun, 1 Mar 2015 18:48:30 +0100 Subject: [PATCH] Fix crash in games that don't support radio style menus Fix regression in ad7d920ce0f57cfec0a35bc942d2a6a8583498e7 GetMenuStyleHandle(MenuStyle_Radio) crashes games, which don't support the radio menu style. The style is never added to the menu manager, if it's not supported, so GetMenuStyleHandle tries to call IsSupported on a nullptr. --- core/MenuStyle_Radio.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/MenuStyle_Radio.cpp b/core/MenuStyle_Radio.cpp index e9b98546..306defd5 100644 --- a/core/MenuStyle_Radio.cpp +++ b/core/MenuStyle_Radio.cpp @@ -83,6 +83,10 @@ void CRadioStyle::OnSourceModLevelChange(const char *mapName) } g_bRadioInit = true; + + // Always register the style. Use IsSupported() to check for validity before use. + g_Menus.AddStyle(this); + const char *msg = g_pGameConf->GetKeyValue("HudRadioMenuMsg"); if (!msg || msg[0] == '\0') { @@ -118,7 +122,6 @@ void CRadioStyle::OnSourceModLevelChange(const char *mapName) } } - g_Menus.AddStyle(this); g_Menus.SetDefaultStyle(this); g_UserMsgs.HookUserMessage(g_ShowMenuId, this, false);