Skip to content

Commit 251f9d0

Browse files
committed
Addendum to 1281716 - Makes "Quit" close the game instantly without last frame-hang, and avoids risk of ungraceful exit code
1 parent 52bca78 commit 251f9d0

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

Client/cefweb/CWebCore.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <cef3/cef/include/cef_parser.h>
1818
#include "WebBrowserHelpers.h"
1919
#include "CWebApp.h"
20+
#include <algorithm>
21+
#include <ranges>
2022

2123
// #define CEF_ENABLE_SANDBOX
2224
#ifdef CEF_ENABLE_SANDBOX
@@ -39,12 +41,15 @@ CWebCore::CWebCore()
3941

4042
CWebCore::~CWebCore()
4143
{
42-
// Unregister schema factories
44+
std::ranges::for_each(m_WebViews, [](const auto& pWebView) {
45+
if (pWebView) [[likely]]
46+
pWebView->CloseBrowser();
47+
});
48+
m_WebViews.clear();
4349
CefClearSchemeHandlerFactories();
4450

45-
// Shutdown CEF
46-
CefShutdown();
47-
51+
// Don't call CefShutdown() here to avoid freeze.
52+
// TerminateProcess (during quit) is called before CCore destruction anyways.
4853
delete m_pRequestsGUI;
4954
delete m_pXmlConfig;
5055
}

Client/core/CCore.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ CCore::CCore()
121121

122122
m_bIsOfflineMod = false;
123123
m_bQuitOnPulse = false;
124-
m_bIsQuitting = false;
125124
m_bDestroyMessageBox = false;
126125
m_bCursorToggleControls = false;
127126
m_bLastFocused = true;
@@ -1204,12 +1203,7 @@ CWebCoreInterface* CCore::GetWebCore()
12041203
void CCore::DestroyWeb()
12051204
{
12061205
WriteDebugEvent("CCore::DestroyWeb");
1207-
// Skip CEF cleanup during quit sequence - TerminateProcess will handle it
1208-
// Doing CefShutdown() here will cause a freeze, and cleanup is unnecessary when terminating
1209-
if (!m_bIsQuitting)
1210-
{
1211-
SAFE_DELETE(m_pWebCore);
1212-
}
1206+
SAFE_DELETE(m_pWebCore);
12131207
m_WebCoreModule.UnloadModule();
12141208
}
12151209

@@ -1502,7 +1496,6 @@ void CCore::Quit(bool bInstantly)
15021496
{
15031497
if (bInstantly)
15041498
{
1505-
m_bIsQuitting = true; // Skip CEF cleanup to prevent CefShutdown freeze
15061499
AddReportLog(7101, "Core - Quit");
15071500
// Show that we are quiting (for the crash dump filename)
15081501
SetApplicationSettingInt("last-server-ip", 1);
@@ -1516,13 +1509,13 @@ void CCore::Quit(bool bInstantly)
15161509
// Destroy the client
15171510
CModManager::GetSingleton().Unload();
15181511

1519-
// Destroy ourself
1512+
// Use TerminateProcess before destroying CCore to ensure clean exit code
1513+
TerminateProcess(GetCurrentProcess(), 0);
1514+
1515+
// Destroy ourself (unreachable but kept for completeness)
15201516
delete CCore::GetSingletonPtr();
15211517

15221518
WatchDogCompletedSection("Q0");
1523-
1524-
// Use TerminateProcess for now as exiting the normal way crashes
1525-
TerminateProcess(GetCurrentProcess(), 0);
15261519
}
15271520
else
15281521
{

Client/core/CCore.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
366366
SString m_strModInstallRoot;
367367

368368
bool m_bQuitOnPulse;
369-
bool m_bIsQuitting;
370369
bool m_bDestroyMessageBox;
371370

372371
bool m_requestNewNickname{false};

0 commit comments

Comments
 (0)