0

this is my code for a Gtk+2 application that uses glade file to build a menu. But when I compile my software it generates following errors:

Gtk-CRITICAL **: IA__gtk_builder_get_object: assertion GTK_IS_BUILDER (builder)' failed Gtk-CRITICAL **: IA__gtk_widget_show: assertionGTK_IS_WIDGET (widget)' failed

drgeoToolbar::drgeoToolbar (geoView *view):
drgeoControl (view)
{
  GError* error = NULL;
  GtkBuilder *xml = gtk_builder_new ();
  GtkWidget *w;

  // Build the toolbars

  // take a reference of each bar item so we can :
  // . adjust their sensitivity
  // . attach a referecence of this class instance


  if (!gtk_builder_add_from_file (xml, DRGEO_GLADEDIR "/drgeo2.glade", &error))
  {
    g_warning ("Couldn't load builder file: %s", error->message);
    g_error_free (error);
  }
  setTopControlerWidget (xml);

  fetchWidgetParent (xml,&p_toolbar, "menuBar",
         (gpointer) this);
  fetchWidgetParent (xml,&p_zoomEntry, "zoomEntry",
         (gpointer) this);
  gtk_entry_set_text (GTK_ENTRY (p_zoomEntry), "100%");
  gtk_builder_connect_signals (xml, &error);
  g_object_unref (G_OBJECT (xml));


  /* short cut bar */

  setShortcutControlerWidget (xml);
  fetchWidgetParent (xml,&p_shortcutBar, "shortcutBar",
         (gpointer) this);
  gtk_builder_connect_signals (xml, &error);
  g_object_unref (G_OBJECT (xml));



  gtk_builder_connect_signals (xml, &error);
  setPointControlerWidget (xml);
  fetchWidgetParent (xml,&p_pointBar, "pointBar", 
         (gpointer) this);
  w = GTK_WIDGET (gtk_builder_get_object(xml, "toolbar"));
  gtk_toolbar_set_tooltips (GTK_TOOLBAR (w), true);
  g_object_unref (G_OBJECT (xml));

  gtk_builder_connect_signals (xml, &error);
  setCurveControlerWidget (xml);
  fetchWidgetParent (xml,&p_curveBar, "curveBar",
         (gpointer) this);
  g_object_unref (G_OBJECT (xml));

  gtk_builder_connect_signals (xml, &error);
  setTransformationControlerWidget (xml);
  fetchWidgetParent (xml,&p_transformationBar, 
         "transformationBar",
         (gpointer) this);
  g_object_unref (G_OBJECT (xml));

  gtk_builder_connect_signals (xml, &error);
  setNumericControlerWidget (xml);
  fetchWidgetParent (xml,&p_numericBar, "numericBar",
         (gpointer) this);
  g_object_unref (G_OBJECT (xml));

  gtk_builder_connect_signals (xml, &error);
  setMacroControlerWidget (xml);
  fetchWidgetParent (xml,&p_macroBar, "macroBar",
         (gpointer) this);
  g_object_unref (G_OBJECT (xml));

  gtk_builder_connect_signals (xml, &error);
  setOtherControlerWidget (xml);
  fetchWidgetParent (xml,&p_otherBar, "otherBar",
         (gpointer) this);
  g_object_unref (G_OBJECT (xml));

} 

Any ideas how can I resolve this?

1 Answer 1

1

Look at the very first error message. You call g_object_unref() on the builder (many times even) yet keep using the builder afterwards.

Remove all but the the last unref call. Same goes for those gtk_builder_connect_signals() calls.

Sign up to request clarification or add additional context in comments.

2 Comments

The toolbar still isn't drawn. #0 0x00007ffff6da9410 in g_log () from /lib/x86_64-linux-gnu/libglib-2.0.so.0 #1 0x0000000000437fca in drgeoToolbar::drgeoToolbar (this=0xf3c010, view=<optimized out>) at drgeo_toolbar.cc:42 This is the backtrace result using gdb, after I did what you suggested. It still crashed. The line number 42 is the line g_warning ("Couldn't load builder file: %s", error->message);
Sounds like the xml file isn't where you think it is. As a general comment: There's several potential problems in the code... I suggest you start from the smallest possible piece of code (like creating a builder from a file) and only add new stuff after you have all the error handling (including returns in the error path) and testing done for that piece.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.