Re: [NEWBIE] GdkPixbuf loading problem



Hi,

Andrej Kacian <tichowrl centrum sk> writes:

> I have a problem loading pixbufs using gdk_pixbuf_new_from_file()
> function. Following code results in segmentation fault: 
> 
> /* begin */
> char buf[64]; 
> GdkPixbuf *p; 
> GError **err; 
> 
> strcpy(buf, "/tmp/image.png"); 
> p = gdk_pixbuf_new_from_file(buf, err); 
> /* end of code */

your usage of GError is wrong, see http://developer.gnome.org/doc/API/2.0/glib/glib-Error-Reporting.html. Correct would be:

GdkPixbuf *pixbuf;
GError    *err = NULL;

pixbuf = gdk_pixbuf_new_from_file ("/tmp/image.png", &err);
if (!pixbuf)
  {
     g_message (err->message);
     g_error_free (err);
  }

I've added some example code to handle the error. If you aren't
interested in the error at all, you may as well use

pixbuf = gdk_pixbuf_new_from_file ("/tmp/image.png", NULL);


Salut, Sven



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