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

2017-03-02 Thread Rúben Rodrigues
Hi,

Still crash after a while.. but needs more time..

What could be?
Thanks
Às 10:41 de 02/03/2017, Gabriele Greco escreveu:

Now, application crash after start, but i think that is because i make
the unref of pixbuf, and in next expose event, fails (i think)...

GdkPixbuf-CRITICAL **: gdk_pixbuf_scale_simple: assertion 'GDK_IS_PIXBUF
(src)' failed

This happens because your original "pixbuf"  is a global object, remove the 
first of the three _unref and you should be fine!

--
Bye,
 Gabry


[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]
  Sem vírus. 
www.avast.com
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

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

2017-03-02 Thread Gabriele Greco
>
>
> Now, application crash after start, but i think that is because i make
> the unref of pixbuf, and in next expose event, fails (i think)...
>
> GdkPixbuf-CRITICAL **: gdk_pixbuf_scale_simple: assertion 'GDK_IS_PIXBUF
> (src)' failed


This happens because your original "pixbuf"  is a global object, remove the
first of the three _unref and you should be fine!

-- 
*Bye,*
* Gabry*
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


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

2017-03-02 Thread Rúben Rodrigues
Thank you very much!!

I'm not sure if i have to do this every time an expose event occurs.. I 
think that i just need on start of application.. But i test on start of 
application, i i don't have widget->allocation values, to make the resize..

Now, application crash after start, but i think that is because i make 
the unref of pixbuf, and in next expose event, fails (i think)...

GdkPixbuf-CRITICAL **: gdk_pixbuf_scale_simple: assertion 'GDK_IS_PIXBUF 
(src)' failed
GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT 
(object)' failed
Gdk-CRITICAL **: IA__gdk_pixbuf_render_pixmap_and_mask_for_colormap: 
assertion 'GDK_IS_PIXBUF (pixbuf)' failed
GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT 
(object)' failed

Às 09:54 de 02/03/2017, Gabriele Greco escreveu:
>> 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, , 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.
>


---
Este e-mail foi verificado em termos de vírus pelo software antivírus Avast.
https://www.avast.com/antivirus

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


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

2017-03-02 Thread Gabriele Greco
>
> 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, , 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*
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


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

2017-03-02 Thread Rúben Rodrigues
Hi,

I have made progress, i use this function to make the resize: pixbuf = 
gdk_pixbuf_scale_simple(pixbuf, widget->allocation.width, 
widget->allocation.height, GDK_INTERP_BILINEAR);

This works, but application blocks after a while..

Here is the Expose event function:

void on_layout_Home_expose_event(GtkWidget *widget, GdkEvent *event, 
gpointer   user_data){
 GtkAllocation allocation;
 GtkWidget*homeWindow;
 GdkPixmap*background;
 GtkStyle*style;

 pixbuf = gdk_pixbuf_scale_simple(pixbuf, widget->allocation.width, 
widget->allocation.height, GDK_INTERP_BILINEAR);
 gdk_pixbuf_render_pixmap_and_mask (pixbuf, , NULL, 0);
 style = gtk_style_new ();

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

 return TRUE;

}

Thanks



Às 17:04 de 01/03/2017, Rúben Rodrigues escreveu:
> Hi,
>
> I'm trying to make something like this 
> http://www.kksou.com/php-gtk2/sample-codes/place-a-background-image-in-GtkWindow-Part-6-align-bottom-right-GdkDrawable-draw_pixbuf.php
>  
> but in C language. For now i just want to fill background image to 
> it's cointainer (GtkLayout), because the container is bigger than 
> image, image is displayed in tiles...
>
> So, i make something like this:
>
> // Load model drawing from file.
> if((pixbuf = gdk_pixbuf_new_from_file("background.png", )) 
> == NULL) {
> g_print("Error.\n");
> return -1;
> }
>
>
> void on_layout_Home_expose_event(GtkWidget *widget, GdkEvent *event, 
> gpointer   user_data){
> GtkAllocation allocation;
> GtkWidget*homeWindow;
> GdkPixmap*background;
> GtkStyle*style;
>
> int w = gdk_pixbuf_get_width(pixbuf);
> int h = gdk_pixbuf_get_height(pixbuf);
>
> gtk_widget_get_allocation(GTK_WIDGET(widget),);
>
>
> // Set picture as background.
> homeWindow = GTK_WIDGET(gtk_builder_get_object(builder, 
> "layout_Home"));
>
> gdk_pixbuf_render_pixmap_and_mask (pixbuf, , NULL, 0);
> style = gtk_style_new ();
> //style->bg_pixmap[0] = background;
> gdk_draw_pixbuf(style->bg_pixmap[0],NULL,pixbuf,0,0,allocation.width-w-10,allocation.height-h-10,-1,-1,GDK_RGB_DITHER_NONE,0,0);
>  
>
>gtk_widget_set_style (GTK_WIDGET(homeWindow), GTK_STYLE(style));
>
> //if(gtk_container_get_children(widget) != NULL){
> //gtk_widget_send_expose 
> (gtk_container_get_children(widget),event);
> //}
>
> return TRUE;
>
> }
>
> But this doesn't work.. and it's normal that program return everytime 
> to expose_event?
>
> Thanks
>
>
> ---
> Este e-mail foi verificado em termos de vírus pelo software antivírus 
> Avast.
> https://www.avast.com/antivirus
>


---
Este e-mail foi verificado em termos de vírus pelo software antivírus Avast.
https://www.avast.com/antivirus

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list