Plain C code bug example for the experts



I told you about this bug some days ago, I get it in my Nim editor https://github.com/ngtk3/NEd

Here is some minimal C code which seems to show a very similar problem.
This is for gtk+-3.18.9 Linux AMD64

The task is to replace a GTK notebook with a paned widget containing two notebooks.
To reproduce:
Compile and run the program.
Click on Tab2 to make textview 2 visible.
Enter a long text line, so that bottom scrollbar becomes visible.
Click on Tab1 to make textview 1 visible.
Click into textview1 so that paned is created.
Resize window by dragging lower left corner of window.

You should get messages like

bassi:4400): Gdk-CRITICAL **: gdk_window_move_resize_internal: assertion 'GDK_IS_WINDOW (window)' failed


It is really not easy to generate this bug, so my assumption is that the problem is
inside of GTK, but maybe I am doing something wrong indeed.


#include <gtk/gtk.h>

// based on https://developer.gnome.org/gtk3/stable/gtk-getting-started.html#id-1.2.3.5
// gcc `pkg-config --cflags gtk+-3.0` -o bassi bassi.c `pkg-config --libs gtk+-3.0`

#include <gtk/gtk.h>

static gboolean
button_press_cb (GtkWidget *widget,
                 GdkEvent  *event,
                 gpointer   window)
{
  GtkWidget *notebook1;
  GtkWidget *notebook2;
  GtkWidget *paned1;
  GtkWidget *textview3;
  GtkWidget *scrolled3;
        notebook1 = gtk_bin_get_child (GTK_BIN(window));
  g_object_ref(notebook1);
  gtk_container_remove (GTK_CONTAINER (window), notebook1);
  paned1 = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
  gtk_paned_pack1 (GTK_PANED (paned1), notebook1, TRUE, FALSE);
  notebook2 = gtk_notebook_new ();
  scrolled3 = gtk_scrolled_window_new (NULL, NULL);
  textview3 = gtk_text_view_new ();
  gtk_container_add (GTK_CONTAINER (scrolled3), textview3);
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook2), scrolled3, NULL);
  gtk_paned_pack2 (GTK_PANED (paned1), notebook2, TRUE, FALSE);
  gtk_container_add (GTK_CONTAINER (window), paned1);
  gtk_widget_show_all (window);
  g_object_unref(notebook1);
        return FALSE;
}

static void
activate (GtkApplication *app,
          gpointer        user_data)
{
  GtkWidget *window;
  GtkWidget *scrolled1;
  GtkWidget *scrolled2;
  GtkWidget *textview1;
  GtkWidget *textview2;
  GtkWidget *notebook1;
  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
  notebook1 = gtk_notebook_new ();
  scrolled1 = gtk_scrolled_window_new (NULL, NULL);
  textview1 = gtk_text_view_new ();
  gtk_container_add (GTK_CONTAINER (scrolled1), textview1);
  g_signal_connect (textview1, "button-press-event", G_CALLBACK (button_press_cb), window);
  scrolled2 = gtk_scrolled_window_new (NULL, NULL);
  textview2 = gtk_text_view_new ();
  gtk_container_add (GTK_CONTAINER (scrolled2), textview2);
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook1), scrolled1, NULL);
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook1), scrolled2, NULL);
  gtk_container_add (GTK_CONTAINER (window), notebook1);
  gtk_widget_show_all (window);
}

int
main (int    argc,
      char **argv)
{
  GtkApplication *app;
  int status;
  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);
  return status;
}


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