Fwd: Resize and place a background image (Expose Event)




This works, but application blocks after a while..


I'm quite sure the problem is that you are leaking at least 2 pixbuf and a
pixmap for every expose event your app receives, and anyway, are you sure
you have to do it every time an expose event is thrown and not only when
the window is resized (configure_event)?




     pixbuf = gdk_pixbuf_scale_simple(pixbuf, widget->allocation.width,


If the original pixbuf has been created just for this operation, this call
leaks a pixbuf object, you shoud do something like:

GdkPixbuf *scaled = gdk_pixbuf_scale_simple(pixbuf,
widget->allocation.width, [...]
g_object_unref(pixbuf);


widget->allocation.height, GDK_INTERP_BILINEAR);
     gdk_pixbuf_render_pixmap_and_mask (pixbuf, &background, NULL, 0);


At this point you leak the second pixbuf, use for instance:
g_object_unref(scaled);


     style->bg_pixmap[0] = background;
     gtk_widget_set_style (GTK_WIDGET(widget), GTK_STYLE(style));


I'm quite sure set_style will increase reference count for 'background', so
after this call you should unref that pixmap:

g_object_unref(background);

You'll receive runtime errors if one of my statements here is not correct,
it's better to add a not needed unref in development and fix it that
release a version that leaks memory.

-- 
*Bye,*
* Gabry*


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