GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Aug 30, 2016 3:11 am

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Segmentation Fault through increment of class data
PostPosted: Sat Oct 27, 2007 2:33 am 

Joined: Sat Oct 27, 2007 2:13 am
Posts: 1
If I declare an Object:
Object *renderer = new Object;

and call the increment function in it:

the variable is incremented by the value specified.
However if I pass the variable as an argument as data in a g_signal_connect:
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(bpress), (gpointer) renderer);

and proceed to use the function:
gint bpress(GtkWidget *widget, GdkEventButton *event, gpointer data)
   //Object *inc;
   //inc = (Object*)data;

when the button is pressed I receive a segmentation fault.
I know the call to the function is working because I checked if the value was getting passed to it with g_print. It only seg faults when the value of xval is changed.

I tried g_print("%d",(int)xval);
If the function is called before it is passed the value is 0, which it should be. If it is called from the button press event the value is way off, suggesting that xval isn't xval anymore, rather it was deleted and it is pointing to a random location.

The class declaration is:
class Object
      int render(cairo_t *cr, GtkWidget *widget);
      void incx(double xInc);
      double xval;

   xval = (double)0;

int Object::render(cairo_t *cr, GtkWidget *widget)
   cr = gdk_cairo_create(widget->window);
   cairo_set_source_rgb(cr, 0, 0, 0);
   cairo_rectangle(cr, xval,xval,100,100);

void Object::incx(double xInc)
   xval += xInc;

Why is the increment causing the seg fault?

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group