diff --git a/src/BizHawk.Client.Common/lua/LuaFile.cs b/src/BizHawk.Client.Common/lua/LuaFile.cs index 93730097e5..d5c2d25d04 100644 --- a/src/BizHawk.Client.Common/lua/LuaFile.cs +++ b/src/BizHawk.Client.Common/lua/LuaFile.cs @@ -56,7 +56,7 @@ namespace BizHawk.Client.Common return; } - if (Thread.State.Status == KeraLua.LuaStatus.OK) + if (State == RunState.Running && Thread.State.Status == KeraLua.LuaStatus.OK) { Thread.State.Yield(0); // we MUST yield this thread, else old references to lua libs might be used (and those may contain references to a Dispose()'d emulator) } diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index acb7eeaa26..3f8b5ad79c 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -209,11 +209,9 @@ namespace BizHawk.Client.EmuHawk return; } - runningScripts = luaLibsImpl.ScriptList.Where(lf => lf.Enabled).ToList(); - - foreach (var file in runningScripts) + foreach (var file in luaLibsImpl.ScriptList) { - luaLibsImpl.CallExitEvent(file); + if (file.Enabled) luaLibsImpl.CallExitEvent(file); luaLibsImpl.RegisteredFunctions.RemoveForFile(file, Emulator); file.Stop(); }