1.1.9 -> 1.1.11 and the order of gtk_widget_show() calls



I upgraded from gtk 1.1.9 to 1.1.11, recompiled a program of mine and
started getting huge amounts of warnings of the following type:

Gdk-CRITICAL **: file gdkpixmap.c: line 55 (gdk_pixmap_new): assertion
`(width != 0) && (height != 0)' failed.

Gdk-CRITICAL **: file gdkdraw.c: line 372 (gdk_draw_pixmap): assertion
`src != NULL' failed.

Gdk-CRITICAL **: file gdkdraw.c: line 372 (gdk_draw_pixmap): assertion
`src != NULL' failed.

And the gdk_draw_pixmap warnings continued endlessly. I tracked the
problem down to the order in which I called gtk_widget_show() on my
various widgets. If I show my top-level window first and then show my
progress-bar, the warning messages appear and my progress-bar stays
invisible. If I show my progress-bar before showing the main window,
they don't. I was under the impression that it's legal to show your
widgets in any order you want, is that correct or are there some
limitations?

Below is a small program which exhibits this behavior. I tried
tracking down the problem more, but it's hard since it seems to
require these exact conditions to appear. If I don't realize my main
window, the problem isn't there. If I don't use a vbox but add the
progress bar straight into the window the problem isn't there. If I
call gtk_box_pack_start with the expand and fill arguments set to TRUE 
the problem isn't there.

This coupled with my total lack of knowledge of GTK internals leads to 
the fact that I'm totally confused whether I'm doing something wrong
in the code below or whether there's a bug in GTK...


#include <gtk/gtk.h>

GtkWidget* pbar=NULL;
int lines_done=0;

gint idle_callback(gpointer ptr)
{
    lines_done++;

    gtk_progress_set_value(GTK_PROGRESS(pbar), (gfloat)lines_done);
    if (lines_done == 1000)
        lines_done=0;
    
    return TRUE;
}

void quit(void)
{
    gtk_exit(0);
}

int
main (int argc, char *argv[])
{
    GtkWidget* window;
    GtkWidget* vbox;
    
    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_realize(window);
    gtk_widget_set_usize(window, 300, 25);

    gtk_signal_connect(GTK_OBJECT(window), "destroy",
                       GTK_SIGNAL_FUNC(quit), NULL);

    vbox = gtk_vbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(window), vbox);
    gtk_widget_show(vbox);
    
    pbar = gtk_progress_bar_new();
    gtk_progress_configure(GTK_PROGRESS(pbar), 0.0, 0.0,
                           1000.0);
    gtk_box_pack_start(GTK_BOX(vbox), pbar, FALSE, FALSE, 0);
    gtk_progress_set_value(GTK_PROGRESS(pbar), 0.0);
    gtk_idle_add(idle_callback, NULL);

    gtk_widget_show(pbar);
    
    gtk_widget_show(window);

/*    gtk_widget_show(pbar); */
    
    gtk_main ();
    
    return 0;
}

--
Osku Salerma - osku@iki.fi - http://www.iki.fi/osku/
I'd give my right arm to be ambidextrous.



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