crashhandler: immediately terminate the game in release mode

This commit is contained in:
goat 2024-06-17 21:23:31 +02:00
parent 5f51ca22e0
commit 979f78a8b6

View file

@ -965,7 +965,7 @@ int main() {
const TASKDIALOG_BUTTON buttons[]{ const TASKDIALOG_BUTTON buttons[]{
{IdButtonRestart, L"Restart\nRestart the game with the above-selected option."}, {IdButtonRestart, L"Restart\nRestart the game with the above-selected option."},
{IdButtonSaveTsPack, L"Save Troubleshooting Info\nSave a .tspack file containing information about this crash for analysis."}, {IdButtonSaveTsPack, L"Save Troubleshooting Info\nSave a .tspack file containing information about this crash for analysis."},
{IdButtonExit, L"Exit\nExit the game."}, {IdButtonExit, L"Exit\nExit without doing anything."},
}; };
config.cbSize = sizeof(config); config.cbSize = sizeof(config);
@ -1060,12 +1060,21 @@ int main() {
pProgressDialog->Release(); pProgressDialog->Release();
pProgressDialog = NULL; pProgressDialog = NULL;
} }
const auto kill_game = [&] { TerminateProcess(g_hProcess, exinfo.ExceptionRecord.ExceptionCode); };
if (shutup) { if (shutup) {
TerminateProcess(g_hProcess, exinfo.ExceptionRecord.ExceptionCode); kill_game();
return 0; return 0;
} }
#if !_DEBUG
// In release mode, we can't resume the game, so just kill it. It's not safe to keep it running, as we
// don't know what state it's in and it may have crashed off-thread.
// Additionally, if the main thread crashed, Windows will show the ANR dialog, which will block our dialog.
kill_game();
#endif
int nButtonPressed = 0, nRadioButton = 0; int nButtonPressed = 0, nRadioButton = 0;
if (FAILED(TaskDialogIndirect(&config, &nButtonPressed, &nRadioButton, nullptr))) { if (FAILED(TaskDialogIndirect(&config, &nButtonPressed, &nRadioButton, nullptr))) {
SetEvent(exinfo.hEventHandle); SetEvent(exinfo.hEventHandle);
@ -1073,7 +1082,7 @@ int main() {
switch (nButtonPressed) { switch (nButtonPressed) {
case IdButtonRestart: case IdButtonRestart:
{ {
TerminateProcess(g_hProcess, exinfo.ExceptionRecord.ExceptionCode); kill_game();
restart_game_using_injector(nRadioButton, *launcherArgs); restart_game_using_injector(nRadioButton, *launcherArgs);
break; break;
} }
@ -1081,7 +1090,7 @@ int main() {
if (attemptResume) if (attemptResume)
SetEvent(exinfo.hEventHandle); SetEvent(exinfo.hEventHandle);
else else
TerminateProcess(g_hProcess, exinfo.ExceptionRecord.ExceptionCode); kill_game();
} }
} }
} }