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:
parent
33af6da5e1
commit
c25ab670e6
@ -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)
|
||||
|
@ -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.
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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"))
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user