0ad/binaries/data/mods/public/gui/session/message_box/QuitConfirmationReplay.js
Vantha 2520c45220 Only call Engine.EndGame right before closing
Since #7786, the GUI tick completed normally after calling
`closePageCallback` instead of being cancelled like previously. Since
`Engine.EndGame` deletes the internal `g_Game` pointer, every Engine call
after it that tried to access `g_Game` caused a segfault.
This patch solves it by moving `Engine.EndGame` to the very end, right
before closing the session page.
In order to follow the convention that only functions directly closing
the page are called `closePageCallback`, that function is in turn
renamed to `closeSession`. Additionally, this allows only resolving
the promise with a bool (`showSummary`) and then only calling
`getNextPageOpenRequest` at the end of `init` for reasons of simplicity.
2026-07-22 23:51:49 +02:00

36 lines
1.1 KiB
JavaScript

/**
* This class is concerned with opening a message box if the game is in replaymode and that replay ended.
*/
class QuitConfirmationReplay extends QuitConfirmation
{
constructor(closeSession)
{
super();
Engine.GetGUIObjectByName("session").onReplayFinished = this.display.bind(this, closeSession);
}
}
QuitConfirmationReplay.prototype.Title =
translateWithContext("replayFinished", "Confirmation");
QuitConfirmationReplay.prototype.Caption =
translateWithContext("replayFinished", "The replay has finished. What do you want to do?");
QuitConfirmationReplay.prototype.Buttons =
[
{
// Translation: Shown in the Dialog that shows up when a replay finishes
"caption": translate("Stay"),
"onPress": resumeGame
},
{
// Translation: Shown in the Dialog that shows up when a replay finishes
"caption": translate("Quit and View Summary"),
"onPress": function() { this.closeSession(true); }
},
{
// Translation: Shown in the Dialog that shows up when a replay finishes
"caption": translate("Quit"),
"onPress": function() { this.closeSession(false); }
}
];