diff --git a/source/gui/GUIManager.cpp b/source/gui/GUIManager.cpp index 701040cb59..9e3766ae44 100644 --- a/source/gui/GUIManager.cpp +++ b/source/gui/GUIManager.cpp @@ -73,9 +73,9 @@ CGUIManager::~CGUIManager() UnregisterFileReloadFunc(ReloadChangedFileCB, this); } -bool CGUIManager::HasPages() +size_t CGUIManager::GetPageCount() const { - return !m_PageStack.empty(); + return m_PageStack.size(); } void CGUIManager::SwitchPage(const CStrW& pageName, ScriptInterface* srcScriptInterface, JS::HandleValue initData) diff --git a/source/gui/GUIManager.h b/source/gui/GUIManager.h index e35ff268a7..fbc83201a3 100644 --- a/source/gui/GUIManager.h +++ b/source/gui/GUIManager.h @@ -59,9 +59,9 @@ public: shared_ptr GetActiveGUI() { return top(); } /** - * Returns whether there are any current pages. + * Returns the number of currently open GUI pages. */ - bool HasPages(); + size_t GetPageCount() const; /** * Load a new GUI page and make it active. All current pages will be destroyed. diff --git a/source/gui/scripting/JSInterface_GUIManager.cpp b/source/gui/scripting/JSInterface_GUIManager.cpp index 89a22e9974..aa79486c52 100644 --- a/source/gui/scripting/JSInterface_GUIManager.cpp +++ b/source/gui/scripting/JSInterface_GUIManager.cpp @@ -39,6 +39,14 @@ void JSI_GUIManager::SwitchGuiPage(ScriptInterface::CxPrivate* pCxPrivate, const void JSI_GUIManager::PopGuiPage(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue args) { + if (g_GUI->GetPageCount() < 2) + { + JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); + JSAutoRequest rq(cx); + JS_ReportError(cx, "Can't pop GUI pages when less than two pages are opened!"); + return; + } + g_GUI->PopPage(pCxPrivate->pScriptInterface->WriteStructuredClone(args)); } diff --git a/source/ps/Game.cpp b/source/ps/Game.cpp index 7fc6e4b76d..54937b7f49 100644 --- a/source/ps/Game.cpp +++ b/source/ps/Game.cpp @@ -320,7 +320,7 @@ PSRETURN CGame::ReallyStartGame() g_NetClient->LoadFinished(); // Call the reallyStartGame GUI function, but only if it exists - if (g_GUI && g_GUI->HasPages()) + if (g_GUI && g_GUI->GetPageCount()) { JS::RootedValue global(cx, g_GUI->GetActiveGUI()->GetGlobalObject()); if (g_GUI->GetActiveGUI()->GetScriptInterface()->HasProperty(global, "reallyStartGame")) diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index d35b2f52df..85cac57c7e 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -1667,7 +1667,7 @@ void CancelLoad(const CStrW& message) LDR_Cancel(); if (g_GUI && - g_GUI->HasPages() && + g_GUI->GetPageCount() && pScriptInterface->HasProperty(global, "cancelOnLoadGameError")) pScriptInterface->CallFunctionVoid(global, "cancelOnLoadGameError", message); }