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

client.reboot_core() causes System.InvalidOperationException error #2571

Closed
Real96 opened this issue Jan 16, 2021 · 4 comments
Closed

client.reboot_core() causes System.InvalidOperationException error #2571

Real96 opened this issue Jan 16, 2021 · 4 comments
Labels
App: EmuHawk Relating to EmuHawk frontend Repro: Fixed/added in 2.6.1 Repro: Regression from 2.5.2 Reproducible bug Should only be added to issues with a `Repro: Affects` label. Tool: Lua Console Relating to the Lua Console (not EmuHawk's Lua API)

Comments

@Real96
Copy link

Real96 commented Jan 16, 2021

Summary

When you run BizHawk and load any lua script with client.reboot_core() inside the code, it will make you get this error:

System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)

Repro

  1. Load any game
  2. run this simple script:
client.reboot_core()
x = 0
while true do
  x = x + 1
  print(x)
 emu.frameadvance()
end

Output

1
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)
2
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)
3
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)
4
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)
5
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)
System.InvalidOperationException: Lua surface is already locked: emu
   in BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(String name, Boolean clear)
   in BizHawk.Client.Common.GuiApi.DrawNew(String name, Boolean clear)

Host env.

  • BizHawk dev build at 26fb9b9; Win10 Home 1809; Intel/NVIDIA
@Real96 Real96 changed the title Lua Core NLua+KopiLua System.InvalidOperationException error client.reboot_core() causes System.InvalidOperationException error Jan 16, 2021
@YoshiRulz YoshiRulz added App: EmuHawk Relating to EmuHawk frontend Repro: Affects 2.5.3 dev Tool: Lua Console Relating to the Lua Console (not EmuHawk's Lua API) labels Jan 16, 2021
@YoshiRulz YoshiRulz self-assigned this Jan 16, 2021
@YoshiRulz
Copy link
Member

YoshiRulz commented Jan 16, 2021

Call stack (repro'd w/ 26fb9b9):

>	EmuHawk.exe!BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(string name, bool clear) Line 1123	C#
 	BizHawk.Client.Common.dll!BizHawk.Client.Common.GuiApi.DrawNew(string name, bool clear) Line 83	C#
 	BizHawk.Client.Common.dll!BizHawk.Client.Common.GuiLuaLibrary.DrawNew(string name, bool? clear) Line 24	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.Win32LuaLibraries.StartLuaDrawing() Line 162	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.ReDraw() Line 978	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.EnableLuaFile(BizHawk.Client.Common.LuaFile item) Line 958	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.LoadLuaFile(string path) Line 356	C#
[...]

edit: I caused this regression with cf90175.

@YoshiRulz YoshiRulz added Repro: Regression from 2.5.2 Reproducible bug Should only be added to issues with a `Repro: Affects` label. labels Jan 16, 2021
@Real96
Copy link
Author

Real96 commented Jan 16, 2021

I don't know if it is better to open another issue, but after getting this error and removing the lua from the lua console, trying to load any other working lua (which doesn't have client.reboot_core() inside its code) will always make you get the error. It is like BizHawk saves the previous lua exectution.
I need to close and reopen the app to make another lua working correctly

YoshiRulz added a commit to YoshiRulz/BizHawk_BranchBackup that referenced this issue Jan 16, 2021
…SEmulators#2571)

Wrapping draw calls in DrawNew/DrawFinish is the responsibility of the script
author. This removes the feature which allowed scripts to draw as soon as they
became enabled.
@YoshiRulz YoshiRulz removed their assignment Jan 16, 2021
adelikat pushed a commit that referenced this issue Jan 16, 2021
YoshiRulz added a commit to YoshiRulz/BizHawk_BranchBackup that referenced this issue Jan 16, 2021
fixes TASEmulators#2571 again
`gui.DrawNew("native")` now throws (I will replace this with something better).
`gui.DrawNew("emu")` and `gui.DrawFinish()` do nothing but print warning
messages, for backwards compatibility. This removes the feature which allowed
scripts to draw as soon as they became enabled. It also removes the feature to
draw without clearing the surface, though that wasn't working (I will try to
reimplement that as well).
YoshiRulz added a commit to YoshiRulz/BizHawk_BranchBackup that referenced this issue Jan 16, 2021
fixes TASEmulators#2571 again
`gui.DrawNew("native")` now throws (I will replace this with something better).
`gui.DrawNew("emu")` and `gui.DrawFinish()` do nothing but print warning
messages, for backwards compatibility. This removes the feature which allowed
scripts to draw as soon as they became enabled. It also removes the feature to
draw without clearing the surface, though that wasn't working (I will try to
reimplement that as well).
YoshiRulz added a commit that referenced this issue Jan 16, 2021
fixes #2571 again
`gui.DrawNew("native")` now throws (I will replace this with something better).
`gui.DrawNew("emu")` and `gui.DrawFinish()` do nothing but print warning
messages, for backwards compatibility. This removes the feature which allowed
scripts to draw as soon as they became enabled. It also removes the feature to
draw without clearing the surface, though that wasn't working.
adelikat pushed a commit that referenced this issue Jan 17, 2021
* Refactor how the "emu" drawing surface is automatically opened/closed

fixes #2571 again
`gui.DrawNew("native")` now throws (I will replace this with something better).
`gui.DrawNew("emu")` and `gui.DrawFinish()` do nothing but print warning
messages, for backwards compatibility. This removes the feature which allowed
scripts to draw as soon as they became enabled. It also removes the feature to
draw without clearing the surface, though that wasn't working.

* Reimplement drawing to "client" surface (see desc.)

Changed surface names in APIs to "emucore" and "client" (not in DisplayManager
yet because I can't be bothered).
Via ApiHawk, `IGuiApi.WithEmuSurface(Action)` has been replaced with
`IGuiApi.WithSurface(DrawingSurfaceID, Action)`, the first param being an enum.
Via Lua (or ApiHawk), pass an extra string param (`DrawingSurfaceID` enum for
ApiHawk) to each `gui.draw*` call.
To make it less verbose, omitting the param is treated as using the default
"emucore" surface, *unless* the helper `gui.use_surface("client")` had been
called, which persists the chosen surface until Lua restarts or it's
overwritten. (The same is done when using `WithSurface` in ApiHawk, though it's
cleared once `WithSurface` returns.)
Along with the new surface names, the old names are still valid in the `surface`
params and `gui.use_surface` for now.

* Propogate enum to DisplayManager, s/Lua/ApiHawk/ in DisplayManager
@Real96
Copy link
Author

Real96 commented Jan 18, 2021

Call stack (repro'd w/ 26fb9b9):

>	EmuHawk.exe!BizHawk.Client.EmuHawk.DisplayManager.LockLuaSurface(string name, bool clear) Line 1123	C#
 	BizHawk.Client.Common.dll!BizHawk.Client.Common.GuiApi.DrawNew(string name, bool clear) Line 83	C#
 	BizHawk.Client.Common.dll!BizHawk.Client.Common.GuiLuaLibrary.DrawNew(string name, bool? clear) Line 24	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.Win32LuaLibraries.StartLuaDrawing() Line 162	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.ReDraw() Line 978	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.EnableLuaFile(BizHawk.Client.Common.LuaFile item) Line 958	C#
 	EmuHawk.exe!BizHawk.Client.EmuHawk.LuaConsole.LoadLuaFile(string path) Line 356	C#
[...]

edit: I caused this regression with cf90175.

I just tested the last commit (253a24e) and the problem is still there. Game boot but the lua window always print the error causing a big lagging.
In previous commit 9cca7c4 the problem is fixed instead.

@Real96
Copy link
Author

Real96 commented Jan 18, 2021

image

YoshiRulz added a commit to YoshiRulz/BizHawk_BranchBackup that referenced this issue Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
App: EmuHawk Relating to EmuHawk frontend Repro: Fixed/added in 2.6.1 Repro: Regression from 2.5.2 Reproducible bug Should only be added to issues with a `Repro: Affects` label. Tool: Lua Console Relating to the Lua Console (not EmuHawk's Lua API)
Projects
None yet
Development

No branches or pull requests

2 participants