Crashes when converting tables to Variant
Hi! I’m new to Godot and still learning how to use lua-gdextension. While experimenting, I noticed some strange crashes and I’m not sure if this is expected behavior or a bug.
local player = {
extends = Node2D,
}
-- Case 1: Lua tables inside Array
function player:test1()
local array1 = {}
local array2 = {}
return Array{array1, array2} -- segfault
end
-- Case 2: Multiple return values
function player:test2()
return {}, 1 -- segfault
end
function player:_process(dt)
self:test1()
self:test2()
end
return player
What I observed return Array{{}} → segfault return {}, 1 → segfault return {} → does not crash return Array{1, 2, 3} → works fine
Is this the correct/expected behavior (Lua tables not allowed, only Godot-native types)? Or should this raise an error instead of crashing?
Originally posted by @modcos in https://github.com/gilzoide/lua-gdextension/discussions/153
Thanks for the clarification.
I tested both 0.5.0 builds:
lua-gdextension+luajit.zip → segfaults with the examples above. lua-gdextension.zip → works fine with the examples, but I occasionally see errors in the debugger at unpredictable times.
Couldn't replicate from latest commit gilzoide/lua-gdextension@bb3b11f, likely fixed already.
@modcos check out the guide in #15 and downloaded the latest build and report whether it still happens.
I tested again with the latest build. Downloaded lua-gdextension+luajit from Actions: link.
Minimal project setup: just a scene with a Node and the script attached (same example from the topic post).
- On the +luajit build, I consistently get segfaults within 1–5 seconds after running.
- On the non-luajit build, the examples usually work, but if I duplicate the
test1()andtest2()calls many times in_process(without a loop, just repeated lines, ~20+ calls each), I also get segfaults.
Example:
function player:_process(dt)
self:test1()
self:test1()
...
self:test2()
self:test2()
end
Environment:
- Godot version:
v4.4.1.stable.official [49a5bc7b6] - Commit tested:
bb3b11f - OS: Windows 10
So it seems the issue is easier to reproduce on the +luajit build, but can also happen on the plain version when the functions are called enough times.
Oh, my bad. I guess I wasn't running it long enough.
Hey folks, thanks for the additional info. I'll check it out at some point. Maybe memory allocations fail at some point and it crashes because of that. We could add an error log whenever Lua allocator function fails and check if that's the case.