Skip to content

Commit 25169ea

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 5359aeb commit 25169ea

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;
@@ -1166,12 +1165,7 @@ CWebCoreInterface* CCore::GetWebCore()
11661165
void CCore::DestroyWeb()
11671166
{
11681167
WriteDebugEvent("CCore::DestroyWeb");
1169-
// Skip CEF cleanup during quit sequence - TerminateProcess will handle it
1170-
// Doing CefShutdown() here will cause a freeze, and cleanup is unnecessary when terminating
1171-
if (!m_bIsQuitting)
1172-
{
1173-
SAFE_DELETE(m_pWebCore);
1174-
}
1168+
SAFE_DELETE(m_pWebCore);
11751169
m_WebCoreModule.UnloadModule();
11761170
}
11771171

@@ -1464,7 +1458,6 @@ void CCore::Quit(bool bInstantly)
14641458
{
14651459
if (bInstantly)
14661460
{
1467-
m_bIsQuitting = true; // Skip CEF cleanup to prevent CefShutdown freeze
14681461
AddReportLog(7101, "Core - Quit");
14691462
// Show that we are quiting (for the crash dump filename)
14701463
SetApplicationSettingInt("last-server-ip", 1);
@@ -1478,13 +1471,13 @@ void CCore::Quit(bool bInstantly)
14781471
// Destroy the client
14791472
CModManager::GetSingleton().Unload();
14801473

1481-
// Destroy ourself
1474+
// Use TerminateProcess before destroying CCore to ensure clean exit code
1475+
TerminateProcess(GetCurrentProcess(), 0);
1476+
1477+
// Destroy ourself (unreachable but kept for completeness)
14821478
delete CCore::GetSingletonPtr();
14831479

14841480
WatchDogCompletedSection("Q0");
1485-
1486-
// Use TerminateProcess for now as exiting the normal way crashes
1487-
TerminateProcess(GetCurrentProcess(), 0);
14881481
}
14891482
else
14901483
{

Client/core/CCore.h

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

369369
bool m_bQuitOnPulse;
370-
bool m_bIsQuitting;
371370
bool m_bDestroyMessageBox;
372371

373372
bool m_bDoneFrameRateLimit;

0 commit comments

Comments
 (0)