bjornbytes / lovr

Lua Virtual Reality Framework
https://lovr.org
MIT License
1.94k stars 135 forks source link

PANIC: unprotected error in call to Lua API (Unknown type 'Channel' (maybe its module needs to be required)) #566

Closed MattRoelle closed 2 years ago

MattRoelle commented 2 years ago

Hi there, I am trying to use threads/channels but I run into this issue when using a channel. I am requiring lovr/lovr.thread from within the code passed to newThread.

I would suspect that the coroutine usage is to blame.

For context, I am attempting to get a Fennel REPL open over STDIO on a separate thread. This approach works well for Love2d and the following repro code is a pretty straight port from the love2d Fennel repl code.

Reproduction

You will receive the error if you run the following repo with lovr: https://github.com/MattRoelle/min-lovr-fennel LOVR Version: LOVR 0.15.0 (Government Goop)

The error occurs on this line You can check the compiled lua for stdio as well and it is fairly readable.

PANIC: unprotected error in call to Lua API (Unknown type 'Channel' (maybe its module needs to be required))

bjornbytes commented 2 years ago

I think I understand what's going on. The Channel is getting passed to Thread:start as one of its arguments, which is causing the error. This was a bug previously reported in #524 which has since been fixed. The code is also pushing a table to the Channel which isn't supported yet, but I don't think that's contributing to the panic. Let me know if I missed anything!

bjornbytes commented 2 years ago

It is possible to work around this in v0.15.0 by popping the object from a Channel instead of passing it to Thread:start