From 9f4e3985851ac0bcd2b1154ce13fa51a7565b227 Mon Sep 17 00:00:00 2001 From: Itms Date: Sat, 11 Jul 2020 14:24:09 +0000 Subject: [PATCH] Fix rooting mistake in CGame::ReallyStartGame, detected by Bellaz89, fixes #5776. Differential Revision: https://code.wildfiregames.com/D2869 Accepted By: Bellaz89 This was SVN commit r23815. --- source/ps/Game.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/ps/Game.cpp b/source/ps/Game.cpp index 670e6da687..b71f23f768 100644 --- a/source/ps/Game.cpp +++ b/source/ps/Game.cpp @@ -295,9 +295,6 @@ int CGame::LoadInitialState() **/ PSRETURN CGame::ReallyStartGame() { - JSContext* cx = m_Simulation2->GetScriptInterface().GetContext(); - JSAutoRequest rq(cx); - // Call the script function InitGame only for new games, not saved games if (!m_IsSavedGame) { @@ -327,9 +324,12 @@ PSRETURN CGame::ReallyStartGame() // Call the reallyStartGame GUI function, but only if it exists if (g_GUI && g_GUI->GetPageCount()) { - JS::RootedValue global(cx, g_GUI->GetActiveGUI()->GetGlobalObject()); - if (g_GUI->GetActiveGUI()->GetScriptInterface()->HasProperty(global, "reallyStartGame")) - g_GUI->GetActiveGUI()->GetScriptInterface()->CallFunctionVoid(global, "reallyStartGame"); + shared_ptr scriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface(); + JSContext* cx = scriptInterface->GetContext(); + JSAutoRequest rq(cx); + JS::RootedValue global(cx, scriptInterface->GetGlobalObject()); + if (scriptInterface->HasProperty(global, "reallyStartGame")) + scriptInterface->CallFunctionVoid(global, "reallyStartGame"); } debug_printf("GAME STARTED, ALL INIT COMPLETE\n");