From e62eb9609245a12070162aca0d3b930f5c2bd03e Mon Sep 17 00:00:00 2001 From: phosit Date: Sun, 14 Dec 2025 21:12:22 +0100 Subject: [PATCH] Allow swapped in pages to close themselves This wasn't possible because init functions are called inside each other and the outer one overwrites the result of the inner one. Now the outer result doesn't overwrite the inner result but stores it to the pointed to location. --- source/gui/GUIManager.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/gui/GUIManager.cpp b/source/gui/GUIManager.cpp index 4acbebfa08..7bc5f7c0ae 100644 --- a/source/gui/GUIManager.cpp +++ b/source/gui/GUIManager.cpp @@ -256,11 +256,15 @@ void CGUIManager::SGUIPage::LoadPage(ScriptContext& scriptContext) if (hotloadData) Script::ReadStructuredClone(rq, hotloadData, &hotloadDataVal); + sendingPromise = std::make_shared(rq.cx); + // Assigning to `sendingPromise` isn't possible after `init` has been called because `init` might + // replace this page. So a local copy has to be made. + const std::shared_ptr localPromise{sendingPromise}; + JS::RootedObject returnObject{rq.cx, gui->CallPageInit(rq, initData, hotloadDataVal, utf8_from_wstring(m_Name))}; - sendingPromise = std::make_shared(rq.cx, - returnObject ? returnObject : JS::NewPromiseObject(rq.cx, nullptr)); + *localPromise = returnObject ? returnObject : JS::NewPromiseObject(rq.cx, nullptr); } JS::Value CGUIManager::SGUIPage::ReplacePromise(ScriptInterface& scriptInterface)