Re: problem using gtk_color_button_get_color
- From: Harring Figueiredo <harringf yahoo com>
- To: Andreas Madsack <gtk bol bb bawue de>, gtk-app-devel-list gnome org
- Cc:
- Subject: Re: problem using gtk_color_button_get_color
- Date: Sun, 19 Dec 2004 17:01:51 -0800 (PST)
--- Andreas Madsack <gtk bol bb bawue de> wrote:
Hello,
when I used gtk_color_button_get_color 2 times I get a segfault.
so I made a simple example with glade.
here is the click-event for a button.
when I click this button 2 times I get a segfault.
void
on_button1_clicked (GtkButton *button,
gpointer user_data)
{
GdkColor *color;
GtkWidget *w;
w=lookup_widget (GTK_WIDGET (button), "colorbutton1");
gtk_color_button_get_color ((GtkColorButton *)w, color);
w=lookup_widget (GTK_WIDGET (button), "label1");
gtk_widget_modify_fg (w, GTK_STATE_ACTIVE, color);
gtk_widget_modify_fg (w, GTK_STATE_NORMAL, color);
}
You are lucky it does not core dump in the first call :P)
GdkColor *color;
GtkWidget *w;
So far you have not allocated memory to any of the above variables, it is
pointing to lala land. Since you did not get a core dump on the first call, it
is pointing to a memory area dedicated to your process.
gtk_color_button_get_color ((GtkColorButton *)w, color);
and since there is no memory alocated, it will cause what you are getting.
Here is how you likely want it done.
GdkColor color;
GtkWidget *w;
Make sure 'w' is pointng to a valid, already allocated widget (in this case
a GtkColorButton) (Perhaps you should add a check to see if glade found you
widget.)
i.e.
w=lookup_widget (GTK_WIDGET (button), "colorbutton1");
g_return_if_fail(w != null);
/* down the road, this will save you a lot of grief when debuging if you
happend to change the name of the button! */
gtk_color_button_get_color ((GtkColorButton *)w, &color);
Now, it should work.
Regards,
Harring.
__________________________________
Do you Yahoo!?
All your favorites on one personal page ? Try My Yahoo!
http://my.yahoo.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]