Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua with TAStudio open: "Can't have lua running in two host threads at a time!" #2172

Closed
ShinobiWannabe opened this issue Jun 27, 2020 · 9 comments

Comments

@ShinobiWannabe
Copy link
Contributor

Exists in 2.4.1 and 2.4.2 Bizhawk. I know this bug does not exist in Bizhawk 2.3.1.

the following lua will have a pop constantly popping up with the attached message. The message contains the error "Can't have lua running in two host threads at a time!"

while true do
savestate.saveslot(5)
savestate.loadslot(4)
emu.frameadvance();
end
lua error

@YoshiRulz YoshiRulz added Repro: Affects 2.4.2 Repro: Regression from 2.3.1 Tool: Lua Console Relating to the Lua Console (not EmuHawk's Lua API) labels Jun 27, 2020
@zeromus
Copy link
Contributor

zeromus commented Jun 27, 2020

works fine for me in 2.4.2 and latest git. You must have forgot an important detail.

@ShinobiWannabe
Copy link
Contributor Author

ShinobiWannabe commented Jun 27, 2020

I did use it with tasstudio open with of course multiple branches. I will compare with and without it tomorrow. Thanks.

@RetroEdit
Copy link
Contributor

Just a note: I have gotten this error before under a few circumstances, but never bothered to report. One in particular occurred when using both an event callback and a while true loop.

@nattthebear
Copy link
Contributor

Gee Bill! How come your mom lets you have lua running in two host threads?

@RetroEdit
Copy link
Contributor

RetroEdit commented Jul 21, 2020

Try this (at a frame other than frame 0). It causes the same error, at least in 2.4.2.

while true do
    tastudio.setplayback(emu.framecount() - 1)
    emu.frameadvance()
end

@RetroEdit RetroEdit changed the title Savestate lua function has popup "Can't have lua running in two host threads at a time!" Lua with TAStudio open: "Can't have lua running in two host threads at a time!" Jul 21, 2020
@RetroEdit RetroEdit added re: Lua API/scripting Relating to EmuHawk's Lua API (not the Lua Console) and removed Tool: Lua Console Relating to the Lua Console (not EmuHawk's Lua API) labels Jul 21, 2020
@suqd
Copy link

suqd commented Jul 22, 2020

I am having the same error in Bizhawk 2.4.2.
If I have TAStudio open and my lua script is loading a savestate or a branch, I get the same error as OP.
Closing TAStudio ""fixes"" the problem, but I'd prefer not having to resort to that.

@RetroEdit
Copy link
Contributor

@adelikat df538c2 was the commit that introduced this problem. It's actually a fairly serious problem because it breaks TAStudio-related Lua functions completely, including tastudio.setplayback and just generally makes anything related to savestates in TAStudio impossible to do with Lua.

Not blaming you for this, since it's probably the Lua code at fault here.

Just for reference, the stack trace is this:

>	BizHawk.Client.Common.dll!BizHawk.Client.Common.LuaLibraryBase.SetCurrentThread(BizHawk.Client.Common.LuaFile luaFile) Line 47	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.Win32LuaLibraries.ResumeScript(BizHawk.Client.Common.LuaFile lf) Line 212	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.ResumeScripts.AnonymousMethod__1() Line 632	C#
 	BizHawk.Client.Common.dll!BizHawk.Client.Common.EnvironmentSandbox.Sandbox(System.Action callback) Line 11	C#
 	BizHawk.Client.Common.dll!BizHawk.Client.Common.LuaSandbox.Sandbox(System.Action callback, System.Action exceptionCallback) Line 50	C#
 	BizHawk.Client.Common.dll!BizHawk.Client.Common.LuaSandbox.Sandbox(NLua.Lua thread, System.Action callback, System.Action exceptionCallback) Line 100	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.ResumeScripts(bool includeFrameWaiters) Line 627	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.UpdateAfter() Line 577	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.ToolFormBase.UpdateValues(BizHawk.Client.Common.ToolFormUpdateType type) Line 31	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.ToolManager.UpdateToolsAfter() Line 674	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.TAStudio.UpdateOtherTools() Line 1002	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.TAStudio.LoadState(System.Collections.Generic.KeyValuePair<int, System.IO.Stream> state) Line 992	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.TAStudio.StartAtNearestFrameAndEmulate(int frame, bool fromLua, bool fromRewinding) Line 936	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.TAStudio.GoToFrame(int frame, bool fromLua, bool fromRewinding) Line 37	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.TAStudioLuaLibrary.SetPlayback(object frame) Line 158	C#
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	NLua.dll!NLua.Method.LuaMethodWrapper.Call(KopiLua.LuaState luaState)	Unknown
 	KopiLua.dll!KopiLua.Lua.LuaDPreCall(KopiLua.LuaState L, KopiLua.Lua.LuaTypeValue func, int nresults)	Unknown
 	KopiLua.dll!KopiLua.Lua.luaV_execute(KopiLua.LuaState L, int nexeccalls)	Unknown
 	KopiLua.dll!KopiLua.Lua.LuaDRawRunProtected(KopiLua.LuaState L, KopiLua.Lua.Pfunc f, object ud)	Unknown
 	KopiLua.dll!KopiLua.Lua.LuaResume(KopiLua.LuaState L, int nargs)	Unknown
 	NLua.dll!NLua.Lua.Resume(int narg)	Unknown
 	EmuHawk.exe!BizHawk.Client.EmuHawk.Win32LuaLibraries.ResumeScript(BizHawk.Client.Common.LuaFile lf) Line 214	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.ResumeScripts.AnonymousMethod__1() Line 632	C#
 	BizHawk.Client.Common.dll!BizHawk.Client.Common.EnvironmentSandbox.Sandbox(System.Action callback) Line 11	C#
 	BizHawk.Client.Common.dll!BizHawk.Client.Common.LuaSandbox.Sandbox(System.Action callback, System.Action exceptionCallback) Line 50	C#
 	BizHawk.Client.Common.dll!BizHawk.Client.Common.LuaSandbox.Sandbox(NLua.Lua thread, System.Action callback, System.Action exceptionCallback) Line 100	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.ResumeScripts(bool includeFrameWaiters) Line 627	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.UpdateAfter() Line 577	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.ToolFormBase.UpdateValues(BizHawk.Client.Common.ToolFormUpdateType type) Line 31	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.ToolManager.UpdateToolsAfter() Line 674	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.ReDraw() Line 973	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.EnableLuaFile(BizHawk.Client.Common.LuaFile item) Line 956	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.ToggleLuaScript(BizHawk.Client.Common.LuaFile file) Line 1564	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.ToggleScriptMenuItem_Click(object sender, System.EventArgs e) Line 933	C#

@YoshiRulz
Copy link
Member

If this is a threading issue, would an equivalent ext. tool also crash?

@adelikat adelikat modified the milestones: 2.5.1, 2.5.2 Sep 12, 2020
@YoshiRulz YoshiRulz added the Repro: Patch pending Potentially fixed in dev build, see readme for download label Sep 27, 2020
@RetroEdit
Copy link
Contributor

Looks like e4d4c3a indeed fixed this. I guess I was wrong about savestate also being broken, or maybe this also fixed that somehow?

Possibly related, I wonder if memorysavestate causes problems with TAStudio, but if it does have more subtle problems, that's probably a separate issue at this point.

@YoshiRulz YoshiRulz added Repro: Fixed/added in 2.5.2 and removed Repro: Affects 2.4.2 Repro: Patch pending Potentially fixed in dev build, see readme for download labels Sep 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants