Re: Reference to a C++ object in GTK+ callbacks



On 12/13/05, Paul Santa Maria <paulsm1021 yahoo com> wrote:
I'm coding in C++, but using the "raw" GTK+ C
libraries.
I'm doing similiar for a game I'm making.

   ------------------
gboolean
play_cb (gpointer data)
{
  // Deference the object pointer to do the actual work
  AnimationFile *ani = (AnimationFile *)data;
  ani->start ();
}
Are you sure that is the right style for that callback?
static void
rocket_cb(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
        class city_node *city=static_cast<class city_node *>(data);
        global_game.rocket_up(*city);
        city->update_targets();
        each_tick(NULL);
}
is what I have for one of my callbacks.
Maybe do a printf("%p",ani); and a printf("%p",m_animation);
to really make sure they point to the same thing.

"ani->start()" works fine outside of the callback.  I know my Animation object has been
successfully created and that "m_animation" points to it before I call gtk_signal_connect().
Good does ani point to the same thing once inside the callback as
m_animation points to outside the callback?

--
http://dmoz.org/profiles/pollei.html
http://sourceforge.net/users/stephen_pollei/
http://www.orkut.com/Profile.aspx?uid=2455954990164098214
http://stephen_pollei.home.comcast.net/



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