love2d / love

LÖVE is an awesome 2D game framework for Lua.
https://love2d.org
Other
4.84k stars 388 forks source link

love.threaderror isn't called if error message is empty #1775

Closed EngineerSmith closed 2 years ago

EngineerSmith commented 2 years ago
local t = love.thread.newThread([[
error()
]])
t:start()

The above code doesn't show default love.threaderror as expected (or a custom set love.threaderror). Not a massive bug - but something to be aware of if no error message is given

thegrb93 commented 2 years ago

Looks intentional https://github.com/love2d/love/blob/8e7fd10b6fd9b6dce6d61d728271019c28a7213e/src/modules/thread/LuaThread.cpp#L106-L107

zorggn commented 2 years ago

But if you look at the code above that, you'll see this: https://github.com/love2d/love/blob/8e7fd10b6fd9b6dce6d61d728271019c28a7213e/src/modules/thread/LuaThread.cpp#L89-L90 I might be wrong, but, onError gets called by that if error's not empty... yet inside onError, it is tested if it's empty again, which it can't be?

thegrb93 commented 2 years ago

There's probably other cases onError may be triggered

zorggn commented 2 years ago

In any case, i'd assume that an empty error call should still pass an empty string to threaderror since an error was raised.

slime73 commented 2 years ago

Yes, I think the core problem with the code is that it's using the error string variable to store the error message and as a flag to check if an error has occurred, so it assumes there's no error if the error message is empty. It should fix the bug if those two concepts are split up (for example by adding a didError boolean variable or something.)