divyang4481 / bizhawk

Automatically exported from code.google.com/p/bizhawk
0 stars 0 forks source link

Problems with N64hawk and registered functions in Lua #244

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
There are some problems using registered functions with n64hawk. Here is a 
sample broken script which will cause bizhawk to deadlock:

function print_input()
  console.log(joypad.get())
end

event.oninputpoll(print_input)

This similar script works as expected:

while true do
  console.log(joypad.get())

  emu.frameadvance()
end

If there is an error in a registered function it can crash bizhawk instead of 
just being displayed in the lua console. Here is a sample script where "handle" 
is not defined causing a lua error and resulting in bizhawk crashing:

function print_input()
  handle:write(0)
end

event.onframeend(print_input)

Here is a similar script with the same problem, but this time the error message 
is displayed on the console:

while true do
  handle:write(0)

  emu.frameadvance()
end

Original issue reported on code.google.com by pjga...@gmail.com on 11 Aug 2014 at 10:53

GoogleCodeExporter commented 9 years ago
Where are we on this?  At one point it was guessed that this was a wrong-thread 
issue, but I haven't followed it since then.

Original comment by goyu...@gmail.com on 26 Aug 2014 at 6:03

GoogleCodeExporter commented 9 years ago
The first example is definitely a wrong-thread issue. The console.log function 
gets called from the N64 thread and the function waits for a chance to modify 
the lua console, which it can't because another thread has a lock on it. That 
other thread is busy waiting for the N64 thread to say it completed a frame, so 
you end up with a deadlock.  

Original comment by pjga...@gmail.com on 26 Aug 2014 at 6:50

GoogleCodeExporter commented 9 years ago
Marking this as an EmuHawk issue since LUA is Core Independent.

Original comment by hegyak on 15 Jan 2015 at 1:01