Background
I work with Watusimoto in a Bitfighter game . We use a variation of LuaWrapper to connect our C ++ objects to Lua objects in the game. We also use a Lua variation called lua-vec to speed up vector operations.
We have been working on a solution to a problem for some time that has eluded us. Random crashes occur that suggest metadata corruption. See here for Watusimoto's post on this. I'm not sure if this is because of the corrupt meta tag and I saw some really strange behavior that I want to ask about here.
Problem manifestation
As an example, we create an object and add it to this level:
t = TextItem.new()
t:setText("hello")
levelgen:addItem(t)
However, the game sometimes (not always) crashes. With an error:
attempt to call missing or unknown method 'addItem' (a nil value)
Using the sentence given in response to the Watusimoto message mentioned above, I changed the last line to the following:
local ok, res = pcall(function() levelgen:addItem(t) end)
if not ok then
local s = "Invalid levelgen value: "..tostring(levelgen).." "..type(levelgen).."\n"
for k, v in pairs(getmetatable(levelgen)) do
s = s.."meta "..tostring(k).." "..tostring(v).."\n"
end
error(res..s)
end
This returns a metathe for levelgenif something happens if the method was called incorrectly from it.
However, and this is crazy, when it fails and prints the meta meta, the meta meta should be exactly the same (with the right challenge addItemand all). If I print the metathe to load levelgenwhen the script loads, and if the pcallabove is unsuccessful , they are identical, each call and pointer to userdata will be the same as it should be.
As if the metathete for levelgenspontaneously disappears randomly.
Can anyone understand what is going on?
thank
: levelgen. , TestItem, . levelgen:addItem(t), t:setText("hello") missing or unknown method 'setText' (a nil value)