mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
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.
This commit is contained in:
parent
3c1cd89ae6
commit
997af452d0
|
@ -160,14 +160,17 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
|
||||||
static CButtonContainer s_ButtonOk;
|
static CButtonContainer s_ButtonOk;
|
||||||
if(DoButton_Menu(&s_ButtonOk, Localize("Ok"), 0, &Ok) || UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
|
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"))
|
if(!str_endswith(m_aCurrentDemoFile, ".demo"))
|
||||||
str_append(m_aCurrentDemoFile, ".demo", sizeof(m_aCurrentDemoFile));
|
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"));
|
str_copy(m_aDemoPlayerPopupHint, Localize("Please use a different name"));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
char aPath[IO_MAX_PATH_LENGTH];
|
char aPath[IO_MAX_PATH_LENGTH];
|
||||||
str_format(aPath, sizeof(aPath), "%s/%s", m_aCurrentDemoFolder, m_aCurrentDemoFile);
|
str_format(aPath, sizeof(aPath), "%s/%s", m_aCurrentDemoFolder, m_aCurrentDemoFile);
|
||||||
|
|
||||||
|
@ -512,7 +515,8 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
|
||||||
static CButtonContainer s_SliceSaveButton;
|
static CButtonContainer s_SliceSaveButton;
|
||||||
if(DoButton_FontIcon(&s_SliceSaveButton, "\xEF\x80\xBD", 0, &Button, IGraphics::CORNER_ALL))
|
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_aDemoPlayerPopupHint[0] = '\0';
|
||||||
m_DemoPlayerState = DEMOPLAYER_SLICE_SAVE;
|
m_DemoPlayerState = DEMOPLAYER_SLICE_SAVE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue