After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 568862 - Cannot use gdk-pixbuf functions without initializing gdk
Cannot use gdk-pixbuf functions without initializing gdk
Status: RESOLVED NOTABUG
Product: gdk-pixbuf
Classification: Platform
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2009-01-23 15:45 UTC by Josselin Mouette
Modified: 2010-07-10 04:06 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Josselin Mouette 2009-01-23 15:45:43 UTC
[ Original report from David Madore: http://bugs.debian.org/508375 ]

The page <URL: file:///usr/share/gtk-doc/html/gdk-pixbuf/apas02.html
 >, or, alternatively, <URL:
http://library.gnome.org/devel/gdk-pixbuf/2.12/apas02.html > contains
the statement: "The gdk-pixbuf library does not need to be
initialized".  This is false, as the following trivial program shows:

/* --- cut after --- */
#include <stdio.h>
#include <stdlib.h>

#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>

/* Compile with
gcc -o stupid stupid.c -O6 -Wall -std=c99 -Wextra `pkg-config --cflags --libs gdk-pixbuf-2.0`
 */

#define WIDTH 320
#define HEIGHT 240
#define ROWSTRIDEPX (WIDTH)
#define ROWSTRIDE (ROWSTRIDEPX*3)

unsigned char image[HEIGHT][ROWSTRIDEPX][3];

GdkPixbuf *img;

int
main (void)
{
  img = gdk_pixbuf_new_from_data ((const guchar *)image,
                                  GDK_COLORSPACE_RGB, FALSE, 8,
                                  WIDTH, HEIGHT, ROWSTRIDE,
                                  NULL, NULL);
  exit (EXIT_SUCCESS);
}
/* --- cut before --- */

This program causes a segmentation fault after the following
errors/warnings:

(process:9342): GLib-GObject-CRITICAL **: /build/buildd/glib2.0-2.16.6/gobject/gtype.c:2248: initialization assertion failed, use IA__g_type_init() prior to this function

(process:9342): GLib-CRITICAL **: g_once_init_leave: assertion `initialization_value != 0' failed

(process:9342): GLib-GObject-CRITICAL **: g_object_new: assertion `G_TYPE_IS_OBJECT (object_type)' failed
zsh: segmentation fault  ./stupid

This segfault goes away when gdk_init() or gtk_init() is used, so it
seems to be an initialization problem: either the doc is wrong, in
which case it should be corrected to explain how and when the library
should be initialized, or it's a gdk-pixbuf bug.

I would prefer this to be counted as a bug against gdk-pixbuf, because
there ought to be a way to manipulate in-core pixbufs (to save image
files to disk) without linking in gdk or gtk.
Comment 1 Emmanuele Bassi (:ebassi) 2009-01-23 16:16:17 UTC
the documentation is correct: there is no gdk-pixbuf initialization function, nor one is needed.

GdkPixbuf is a GObject, so you need to initialize the GType system using g_type_init(); this has nothing to do with GdkPixbuf, as it is required by every piece of code that makes use of the GObject type system. the actual warning text is telling you what to do.

gdk_init() and gtk_init() call g_type_init() for you, that's why the warnings go away when you call either of them.
Comment 2 Claudio Saavedra 2009-01-25 10:54:23 UTC
I think it wouldn't hurt adding a small note to the docs saying that g_type_init() still needs to be called.