lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Alright. Having done a bit more experimenting, I've determined that not just
any access to my Viewport objects which have been passed from Lua causes a
segfault: only the ones where I use Lua arguments as indexes to arrays does
this happen, as in the following:

int api_viewport_translaterd(lua_State *client_state) // Relatively
translate a viewport directionally
{
 // viewport_translaterd(userdata viewport_pointer, number pitch, number
yaw, number roll, number distance)

 if ((lua_gettop(client_state) >= 5) && (lua_tag(client_state, 1) ==
Viewport_tag))
 {
  Viewport *this_viewport = (Viewport *) lua_touserdata(client_state, 1);
  int distance = (int) lua_tonumber(client_state, 5);

  cerr << "The tag of the first argument to viewport_translaterd() is " <<
lua_tag2name(client_state, lua_tag(client_state, 1)) << '\n';

  // Must use trig to find x/y/z values
  // These lines cause segfaults:
  this_viewport->camera_x += sin_lookup[(int) lua_tonumber(client_state, 3)]
* distance; // sin yaw * distance
  this_viewport->camera_y += sin_lookup[(int) lua_tonumber(client_state, 4)]
* distance; // sin roll * distance
  this_viewport->camera_z += sin_lookup[(int) lua_tonumber(client_state, 2)]
* distance; // sin pitch * distance
 }

 return 0;
}

sin_lookup is initialized to be an array of 1001 elements, and the arguments
to the function are checked ahead of time to ensure they fall within these
limits. Is there something wrong with the way I'm indexing the array?

Thanks, Philip Bock

----- Original Message -----
From: "Philip Bock" <phil@flamewars.org>
To: "Multiple recipients of list" <lua-l@tecgraf.puc-rio.br>
Sent: Thursday, November 22, 2001 10:17 PM
Subject: Re: Userdata and methods


> Thanks for pointing out that typo! I'm very new to Lua, so I'm afraid I
> don't have a clear idea of what the usual bug-hunting procedure is. So far
> I've been relying on my console output to find problems. Is there any good
> documentation on debugging lua code anywhere?
>
> Thanks, Philip Bock
>
> ----- Original Message -----
> From: "Edgar Toernig" <froese@gmx.de>
> To: "Multiple recipients of list" <lua-l@tecgraf.puc-rio.br>
> Sent: Thursday, November 22, 2001 9:50 PM
> Subject: Re: Userdata and methods
>
>
> > Philip Bock wrote:
> > >
> > > All console_write() does is output it's (string) argument to
> > > cerr, so I can't see how it should be generating a segfault.
> >
> > Me neither.  The code you posted looks correct (except a typo,
> > console_wirte instead of console_write; but that should not
> > generate a segfault).  Maybe you should start applying the
> > usual bug hunting procedures ;-)
> >
> > Ciao, ET.
> >
> >
>
>
>