[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Table crash on callback
- From: "Wesley Smith" <wesley.hoke@...>
- Date: Thu, 22 Mar 2007 11:58:52 -0700
Hi,
I'm trying to track down a nasty crashing problem with Lua tables. In
the LuaODE module, there is a callback for collision detection. I
pass in to C a reference to a Lua function and if a collision is
detected, I call that function. As an example:
function collisionDetection(data, o1, o2)
print(data)
print(tostring(o1) .. " " .. tostring(o2))
end
I'm having problems when I try to create a new field in a table within
the callback like this:
strings = {}
function collisionDetection(data, o1, o2)
strings[ tostring(o1) ]
end
Here's the crash stack trace.
Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x06b3afd8
0 com.yourcompany.Lua 0x050a1f38 newkey + 208
1 com.yourcompany.Lua 0x050a3ab8 luaV_settable + 80
2 com.yourcompany.Lua 0x050a48b0 luaV_execute + 1012
3 com.yourcompany.Lua 0x05093c38 luaD_call + 136
4 com.yourcompany.Lua 0x05088304 lua_call + 44
What's interesting if that if I use table.insert instead I get no crashes:
strings = {}
function collisionDetection(data, o1, o2)
table.insert(strings, tostring(o1))
end
This behavior isn't unique to luaODE. I've noticed it with other
modules that have callbacks into Lua functions as well. Anyone have
an idea what could be going on here? All of this stuff is happening
in the main thread.
thanks,
wes