From 997af452d043abcf91a76eefe4660bec9492da91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 24 Oct 2022 20:14:04 +0200 Subject: [PATCH] Fix crash when cutting a demo opened from command line When playing a demo without opening the demo menu first, i.e. from command line argument or with `play` command from the main menu, clicking the demo slice button crashes the game, as the code tries to use the filename of the currently selected demo while there is no demo selected, i.e. `m_DemolistSelectedIndex == -1`. Also, when using the play command after opening the demo menu, the initial filename selected for cutting was incorrectly set to the currently selected demo. This is fixed by getting the name of the current demo file from the demo player instead, when cutting a demo. Though the cut demo will be saved to the last demo folder selected (or the demos directory) instead of being saved to the same directory as the original demo. --- src/game/client/components/menus_demo.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index 5a6dd251c..27dbeda9e 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -160,14 +160,17 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) static CButtonContainer s_ButtonOk; if(DoButton_Menu(&s_ButtonOk, Localize("Ok"), 0, &Ok) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER)) { + char aDemoName[IO_MAX_PATH_LENGTH]; + DemoPlayer()->GetDemoName(aDemoName, sizeof(aDemoName)); + str_append(aDemoName, ".demo", sizeof(aDemoName)); + if(!str_endswith(m_aCurrentDemoFile, ".demo")) str_append(m_aCurrentDemoFile, ".demo", sizeof(m_aCurrentDemoFile)); - if(str_comp(m_vDemos[m_DemolistSelectedIndex].m_aFilename, m_aCurrentDemoFile) == 0) + if(str_comp(aDemoName, m_aCurrentDemoFile) == 0) str_copy(m_aDemoPlayerPopupHint, Localize("Please use a different name")); else { - char aPath[IO_MAX_PATH_LENGTH]; str_format(aPath, sizeof(aPath), "%s/%s", m_aCurrentDemoFolder, m_aCurrentDemoFile); @@ -512,7 +515,8 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) static CButtonContainer s_SliceSaveButton; if(DoButton_FontIcon(&s_SliceSaveButton, "\xEF\x80\xBD", 0, &Button, IGraphics::CORNER_ALL)) { - str_copy(m_aCurrentDemoFile, m_vDemos[m_DemolistSelectedIndex].m_aFilename); + DemoPlayer()->GetDemoName(m_aCurrentDemoFile, sizeof(m_aCurrentDemoFile)); + str_append(m_aCurrentDemoFile, ".demo", sizeof(m_aCurrentDemoFile)); m_aDemoPlayerPopupHint[0] = '\0'; m_DemoPlayerState = DEMOPLAYER_SLICE_SAVE; }