1
0
forked from 0ad/0ad

Don't crash if a JS GUI author calls Engine.PopGuiPage too often.

Differential Revision: https://code.wildfiregames.com/D2255
Tested On: clang 8.0.1, Jenkins
Comments By: Stan
This was SVN commit r22846.
This commit is contained in:
elexis 2019-09-04 15:45:48 +00:00
parent 33af6da5e1
commit c25ab670e6
5 changed files with 14 additions and 6 deletions

View File

@ -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)

View File

@ -59,9 +59,9 @@ public:
shared_ptr<CGUI> 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.

View File

@ -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));
}

View File

@ -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"))

View File

@ -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);
}