[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Table crash on callback
- From: Sam Roberts <sroberts@...>
- Date: Thu, 22 Mar 2007 12:11:44 -0700
On Thu, Mar 22, 2007 at 11:58:52AM -0700, Wesley Smith wrote:
> 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
Where is there a new field being created in that code?
It is invalid syntax:
Lua 5.1.1 Copyright (C) 1994-2006 Lua.org, PUC-Rio
> strings={}
> function collisionDetection(data, o1, o2)
>> strings[ tostring(o1) ]
>> end
stdin:3: '=' expected near 'end'
Do you mean:
function collisionDetection(data, o1, o2)
return strings[tostring(o1)]
end
or
function collisionDetection(data, o1, o2)
strings[tostring(o1)] = o2
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
This is a strange backtrace, what tool is it from? Aren't you on OS X?
Can you provide a backtrace from gdb with a debug build that has line
numbers?
As a guess, you look like you are doing a lua_call(), I suspect that lua
is raising an error on the invalid syntax, and since you aren't using
lua_pcall(), the exception is not being caught, and your app is dying.
Cheers,
Sam