File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -614,8 +614,17 @@ int LuaStateWrapper::RunScriptFunctionObject(const LuabindObjectWrapper* functio
614614 functionObjectArgument->GetLuabindObject ()->push (m_State);
615615 }
616616 }
617-
618617 const std::string& path = functionObject->GetFilePath ();
618+
619+ // Function object may be deleted during the Lua call, making `path` above invalid.
620+ // Find and store the script timings entry now and write to it afterward.
621+ PerformanceMan::ScriptTiming* timing = nullptr ;
622+
623+ // only track time in non-MT scripts, for now
624+ if (&g_LuaMan.GetMasterScriptState () == this ) {
625+ timing = &m_ScriptTimings[path];
626+ }
627+
619628 std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now ();
620629 {
621630 ZoneScoped;
@@ -631,10 +640,9 @@ int LuaStateWrapper::RunScriptFunctionObject(const LuabindObjectWrapper* functio
631640 }
632641 std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now ();
633642
634- // only track time in non-MT scripts, for now
635- if (&g_LuaMan.GetMasterScriptState () == this ) {
636- m_ScriptTimings[path].m_Time += std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count ();
637- m_ScriptTimings[path].m_CallCount ++;
643+ if (timing) {
644+ timing->m_Time += std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count ();
645+ timing->m_CallCount ++;
638646 }
639647
640648 lua_pop (m_State, 1 );
You can’t perform that action at this time.
0 commit comments