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)
//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:
int render(cairo_t *cr, GtkWidget *widget);
void incx(double xInc);
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);
void Object::incx(double xInc)
xval += xInc;
Why is the increment causing the seg fault?