pixbuf problems




decided to make a simple little image viewer just to see what i could do
with gdk-pixbuf, and i'm having problems.

it just loads a list of image files in a directory, displays the first,
then when you type 'n', it displays the next.  it displays the first fine,
but crashes on the next.  here is a small code snippet to illustrate what
it does:

GdkPixbuf *pixbuf = NULL;

void cb_darea_expose (GtkWidget *wid, GdkEventExpose *event, gpointer
data)
{
	gdk_pixbuf_render_to_drawable(data, wid->window,
		wid->style->fg_gc[GTK_STATE_NORMAL], 0, 0,
		0, 0, gdk_pixbuf_get_width(data), 
		gdk_pixbuf_get_height(data),
		GDK_RGB_DITHER_NORMAL, 0, 0);
}

void open_image (gchar *filename)
{
	GtkWidget *darea;

	if ((pixbuf != NULL) && (pixbuf->ref-count > 0))
		gdk_pixbuf_unref(pixbuf); /* destroy pixbuf - refcount
will always be 1 */

	pixbuf = gdk_pixbuf_new_from_file(filename);

	darea = gtk_drawing_area_new();
	gtk_signal_connect(GTK_OBJECT(darea), "expose-event",
		GTK_SIGNAL_FUNC(cb_darea_expose), pixbuf);
	gtk_container_add(GTK_CONTAINER(window), darea); /* window is
somewhere else */

	if (!GTK_WIDGET_VISIBLE(window))
		gtk_widget_show(window);
	gtk_widget_show(darea);
}

some error checking was removed to save space.

on the second run of open_image, it crashes on gdk_pixbuf_unref(pixbuf);
gdb give me the same message it gives me every time a segfault happens,
everyone's favorite:

Program received signal SIGSEGV, Segmentation fault.
0x4030e0eb in free () from /lib/libc.so.5

i doubt it could be a problem, but i'm running on a libc5 system
(slackware 4.0)... some programs/libraries are a bit picky about libc5 vs.
glibc2.  

am i doing something wrong here?  thanks for any help.
j



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