[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: tolua crashes
- From: Christian Vogler <cvogler@...>
- Date: Sun, 21 Oct 2001 11:49:59 -0400
On Sun, Oct 21, 2001 at 08:14:25AM -0500, Fabian Lemke wrote:
> It is C++.
>
> I have explicitly declared the destructor, but it did't seem to help.
> (tried it before posting originally actually)
> I tried the destructer both with and without the (void).
> The behavior is kind of strange. if I do a "new" in place of the
> GetPos (in the lua script calling it), and still no delete call, it
> doesn't have a problem either. Could it have something to do with
> the copying of the object?
Tolua copies and takes ownership of objects that are returned by
value, so it should be deleted properly when the garbage collection
kicks in. The explicit delete() is actually *wrong*, because tolua
will still think that it owns the object, which now does not exist
anymore. Eventually, this could cause crashes of the memory management
subsystem during a gc cycle.
I don't see anything wrong with your pkg snippet, and the code that
tolua generates looks correct to me, too. At this point I have no idea
whether you have uncovered a bug in the tolua libraries, your
compiler, or whether there is something else in the rest of your code
that may corrupt things. We use tolua a lot for the kind of task that
you are describing, including return by value and taking of ownership
and never had any problems, so your problem is kind of weird.
Can you get a stack backtrace of the point where your program crashes
with an illegal instruction?
Another shot in the dark: are you using the tolua class or module
bindings from lua itself (i.e., the tolua_class, tolua_instance,
etc. functions)? These *do* contain a bug that causes corruption of
the heap, but if you don't use them in your scripts, it will not
trigger. And your symptoms don't really match the profile of the bug
anyway. But just in case, also try this patch to tolua:
--- snip ---
RCS file: /home3/cvogler/src/cvs/3rdParty/tolua/src/lib/tolua_gp.c,v
retrieving revision 1.1.1.1.4.1
retrieving revision 1.1.1.1.4.2
diff -u -r1.1.1.1.4.1 -r1.1.1.1.4.2
--- src/lib/tolua_gp.c 2001/03/06 03:50:09 1.1.1.1.4.1
+++ src/lib/tolua_gp.c 2001/03/11 23:43:29 1.1.1.1.4.2
@@ -40,7 +40,13 @@
int tolua_getvalue (lua_State* L, int narg, int def)
{
- return lua_gettop(L)<abs(narg) ? def : narg;
+ if (lua_gettop(L)<abs(narg))
+ {
+ lua_pushnil(L);
+ return lua_gettop(L);
+ }
+ else
+ return narg;
}
int tolua_getbool (lua_State* L, int narg, int def)
--- snip ---
- Christian