lua-fix crashes when scripts terminate

This commit is contained in:
zeromus 2012-07-10 19:40:35 +00:00
parent ec9cf60d6d
commit 3a8fe7c464
4 changed files with 15 additions and 4 deletions

View File

@ -218,15 +218,25 @@ namespace BizHawk.MultiClient
public class ResumeResult public class ResumeResult
{ {
public bool WaitForFrame; public bool WaitForFrame;
public bool Terminated;
} }
public ResumeResult ResumeScript(Lua script) public ResumeResult ResumeScript(Lua script)
{ {
currThread = script; currThread = script;
script.Resume(0); int execResult = script.Resume(0);
currThread = null; currThread = null;
var result = new ResumeResult(); var result = new ResumeResult();
result.WaitForFrame = FrameAdvanceRequested; if (execResult == 0)
{
//terminated
result.Terminated = true;
}
else
{
//yielded
result.WaitForFrame = FrameAdvanceRequested;
}
FrameAdvanceRequested = false; FrameAdvanceRequested = false;
return result; return result;
} }

Binary file not shown.

View File

@ -845,6 +845,7 @@ namespace BizHawk.MultiClient
if (!prohibit) if (!prohibit)
{ {
var result = LuaImp.ResumeScript(s.Thread); var result = LuaImp.ResumeScript(s.Thread);
if(result.Terminated) s.Stop();
s.FrameWaiting = result.WaitForFrame; s.FrameWaiting = result.WaitForFrame;
} }
} }

View File

@ -527,8 +527,8 @@ namespace LuaInterface
int ret = LuaDLL.lua_resume(luaState, narg); int ret = LuaDLL.lua_resume(luaState, narg);
if (ret == 1 /*LUA_YIELD*/) if (ret == 1 /*LUA_YIELD*/)
return 1; //yielded return 1; //yielded
if (ret == 0) //normal termination - what to do? if (ret == 0)
return 0; return 0; //normal termination
//error. throw exception with error message (TBD - debug api to get call stack) //error. throw exception with error message (TBD - debug api to get call stack)
ThrowExceptionFromError(top); ThrowExceptionFromError(top);
return ret; return ret;