Skip to content

Commit

Permalink
lua: fix memory leak causing crash after a few dozen script loads/resets
Browse files Browse the repository at this point in the history
  • Loading branch information
zeromus committed May 10, 2017
1 parent e098546 commit 8bc067c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions BizHawk.Client.Common/lua/LuaFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public enum RunState
public void Stop()
{
State = RunState.Disabled;
Thread.GetTable("keepalives")[Thread] = null;
Thread = null;
}

Expand Down
5 changes: 4 additions & 1 deletion BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class EmuLuaLibrary
public EmuLuaLibrary()
{
Docs = new LuaDocumentation();
_lua["keepalives"] = _lua.NewTable();
}

private FormsLuaLibrary FormsLibrary
Expand Down Expand Up @@ -172,14 +173,16 @@ public Lua SpawnCoroutine(string file)
var content = File.ReadAllText(file);
var main = lua.LoadString(content, "main");
lua.Push(main); // push main function on to stack for subsequent resuming
_lua.GetTable("keepalives")[lua] = 1;
_lua.Pop();
return lua;
}

public void ExecuteString(string command)
{
_currThread = _lua.NewThread();

_currThread.DoString(command);
_lua.Pop();
}

public ResumeResult ResumeScript(Lua script)
Expand Down

0 comments on commit 8bc067c

Please sign in to comment.