[cairo] warning while executing gtk_widget_draw
Uli Schlachter
psychon at znc.in
Tue Aug 12 03:34:00 PDT 2014
Hi,
On 12.08.2014 09:54, Lokesh Chakka wrote:
> I have written one program and I am seeing the following warning:
>
> Gtk-CRITICAL **: gtk_widget_draw: assertion '!widget->priv->alloc_needed'
> failed
This is GTK+ and has not much to do with Cairo. Let's take a look anyway.
> program is as follows:
Missing "#include <gtk/gtk.h>
> main()
> {
> GtkDrawingArea *statistics;
> cairo_surface_t *surface;
> cairo_t *cr;
> GtkWindow *main_window;
>
>
> gtk_init( NULL, NULL );
> statistics = (GtkDrawingArea*)gtk_drawing_area_new();
> surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 120, 120);
> cr = cairo_create ( surface );
> gtk_widget_draw( (GtkWidget*)statistics, cr );
This line is what causes that warning. Let's quote the API docs:
widget: the widget to draw. It must be drawable (see gtk_widget_is_drawable())
and a size must have been allocated
https://developer.gnome.org/gtk3/3.2/GtkWidget.html#gtk-widget-draw
Adding this code tells us that the widget isn't drawable, but I bet that it
doesn't have a size allocated yet, too.
puts(gtk_widget_is_drawable((GtkWidget*)statistics) ? "yes" : "no");
> cairo_surface_write_to_png( surface, "one.png" );
> main_window = (GtkWindow*)gtk_window_new(GTK_WINDOW_TOPLEVEL);
>
> g_signal_connect(G_OBJECT(main_window),"destroy",G_CALLBACK(gtk_main_quit),NULL);
> gtk_container_add (GTK_CONTAINER (main_window),(GtkWidget*)statistics);
> gtk_widget_show_all((GtkWidget*)main_window);
>
> gtk_main();
> }
Cheers,
Uli
--
- He made himself, me nothing, you nothing out of the dust
- Er machte sich mir nichts, dir nichts aus dem Staub
More information about the cairo
mailing list