1
0
forked from mirrors/0ad

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.
This commit is contained in:
phosit
2025-12-14 21:12:22 +01:00
parent 426ec45751
commit e62eb96092
+6 -2
View File
@@ -256,11 +256,15 @@ void CGUIManager::SGUIPage::LoadPage(ScriptContext& scriptContext)
if (hotloadData)
Script::ReadStructuredClone(rq, hotloadData, &hotloadDataVal);
sendingPromise = std::make_shared<JS::PersistentRootedObject>(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<JS::PersistentRootedObject> localPromise{sendingPromise};
JS::RootedObject returnObject{rq.cx, gui->CallPageInit(rq, initData, hotloadDataVal,
utf8_from_wstring(m_Name))};
sendingPromise = std::make_shared<JS::PersistentRootedObject>(rq.cx,
returnObject ? returnObject : JS::NewPromiseObject(rq.cx, nullptr));
*localPromise = returnObject ? returnObject : JS::NewPromiseObject(rq.cx, nullptr);
}
JS::Value CGUIManager::SGUIPage::ReplacePromise(ScriptInterface& scriptInterface)