Re: (gtk_pixmap_new): assertion `val != NULL' failed



On Thu, Jun 07, 2001 at 01:42:54PM +0200, Ronald Bultje wrote:
> Hi Helmethead,
> 
> >Have you ever tried doing this when you were learning C:
> [nice code]
> 
> This is true.
> 
> >That's the same reason why ronald's proposal won't work. Mine will tho
> >unless I've made some silly screw up too :)
> >By the way I didn't make much sense when I was talking about the cause >of
> the segfault, I was confusing myself. Are you sure it was on the
> >line you said it was? Did you actually try out the g_prints to see if
> >they print?
> 
> But this is not. Because I work with pointers, so the data should be saved.
> Right? Or am I really missing a big big big big point here?

Actually, that's not true :)
To pass a variable to a function so the function can modify it, you need to pass the address of the variable (like the mask argument to gdk_pixmap_colormap_create_from_xpm_d). That means the function parameter's type is another level of pointerness (indirection is the technical word) past your original variable. If your original variable is an int, the function has to take int*. If the original variable is GtkWidget*, the function has to take a GtkWidget**.

I'll use your example for another example (heh)

> I do see your point here - but as far as I see my code did work with
> pointers - so the data should be kept in place.
> 
> ---
> #include "image.xpm"
> void create_pixmap(GtkWidget *w) {

  void create_pixmap(GtkWidget **w) {

>   GdkPixmap *pixmap;
>   GdkBitmap *mask;
>   pixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL,
>      gtk_widget_get_default_colormap(),
>      &mask, NULL, (gchar **)image_xpm);
>   w = gtk_pixmap_new (pixmap, mask);

    *w = gtk_pixmap_new (pixmap, mask);

> }
> void test() {
>   GtkWidget *w = NULL;
>   create_pixmap(w);

    create_pixmap(&w);

>   if (w == NULL) g_print("I am stupid\n");
>   else g_print("I am not that stupid\n");
> }
> ---




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