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

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



How about trying gdb, seeing what the value of ani is at the time of the
crash.  How about a backtrace?

It's hard to debug your problem as described.  But I have a feeling with
some minimal gdb'ing you can find the bug yourself.

-Andrew

On Tue, 2005-12-13 at 16:00 -0800, Paul Santa Maria wrote:
> Hi -
> 
> I'm using the GTK+ 2.6.4 that came with Suse 9.3.  I'm coding in C++, but using the "raw" GTK+ C
> libraries.
> 
> I'm trying to pass a pointer to one of my C++ classes into a callback, so that I can call a method
> on that class.  The code looks like this:
> 
> 1. less hbaview.h =>
>    --------------
> class HbaviewApp
> {
>   ...
> private:
>   AnimationFile *m_animation;
>   ...
> 
> class Hbafile : public AnimationFile
> {
> public:
>   Hbafile (GtkWidget *da);
>   virtual ~Hbafile ();
>   virtual void open (const char *fname);
>   virtual void close ();
>   virtual void start ();
>   ...
> 
> 2. less HbaviewApp.cpp =>
>    -------------------
> void init ()
>   ...
>   GtkWidget *play = 
>     gtk_image_menu_item_new_from_stock (
>       "gtk-media-play", accel_group);
>   gtk_widget_show (play);
>   gtk_container_add (GTK_CONTAINER (menu3), play);
>   gtk_signal_connect (GTK_OBJECT (play), "activate",
>                       G_CALLBACK (play_cb), m_animation);
>   ...
> 
> 3. less callbacks.cpp =>
>    ------------------
> gboolean
> play_cb (gpointer data)
> {
>   // Deference the object pointer to do the actual work
>   AnimationFile *ani = (AnimationFile *)data;
>   ani->start ();
> }
> 
> "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().
> 
> But it crashes with a signal SIGSEGV, Segmentation fault when the play_cb callback tries to call
> ani->start().
> 
> Any idea what I might be doing wrong?
> 
> Or tips for debugging the problem?
> 
> Thanx in advance!
>    
> 
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


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