After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 589267 - Crash when Gtk::Builder::get_widget() doesn't find the specified widget
Crash when Gtk::Builder::get_widget() doesn't find the specified widget
Status: RESOLVED FIXED
Product: gtkmm
Classification: Bindings
Component: general
2.16.x
Other All
: Normal critical
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2009-07-21 16:00 UTC by Alexander Shaduri
Modified: 2009-07-23 17:18 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Alexander Shaduri 2009-07-21 16:00:47 UTC
Steps to reproduce:
If I use the Gtk::Builder::get_widget() function to get a widget that doesn't exist in the .ui file, I get the following:
(example:15351): gtkmm-CRITICAL **: gtkmm: object `DialogBasic_' not found in GtkBuilder file.
Segmentation fault

Note that this happens even if I try to catch the exceptions. The following example (modified from gtkmm-documentation-2.16.0/examples/book/builder/basic/main.cc) demonstrates the issue.


#include <gtkmm.h>
#include <iostream>

int main (int argc, char **argv)
{
  Gtk::Main kit(argc, argv);

  //Load the GtkBuilder file and instantiate its widgets:
  Glib::RefPtr<Gtk::Builder> refBuilder = Gtk::Builder::create();
  try {
    refBuilder->add_from_file("basic.ui");
  }
  catch(const Glib::Error& ex) {
    std::cerr << "Gtk::Builder::create() error: " << ex.what() << std::endl;
    return 1;
  }

  Gtk::Dialog* pDialog = 0;

  try {
    // Notice the invalid name!
    refBuilder->get_widget("DialogBasic_DOES_NOT_EXIST", pDialog);
  }
  catch(const Glib::Error& ex) {
    std::cerr << "get_widget() error: " << ex.what() << std::endl;
  }

  if(pDialog) {
    kit.run(*pDialog);
  }

  return 0;
}


Stack trace:
  • #0 Gtk::Builder::get_widget_checked
    at builder.cc line 265
  • #1 main
    at /usr/include/gtkmm-2.4/gtkmm/builder.h line 474


Other information:
Tested with gtkmm 2.16.0, gtk2-2.16.4 on openSUSE 11.1 x86_64.
Comment 1 Alexander Shaduri 2009-07-21 16:03:44 UTC
Forgot to add, the "basic.ui" file comes from gtkmm-documentation-2.16.0/examples/book/builder/basic/basic.ui . You can just drop the above example as main.cc in there and it will compile. Also, this is somewhat related to http://bugzilla.gnome.org/show_bug.cgi?id=548022
Comment 2 Murray Cumming 2009-07-23 17:18:09 UTC
This should be fixed by this commit in master, which I will cherry-pick to other branches tomorrow too:

2009-07-23  Murray Cumming  <murrayc@murrayc.com>

	Gtk::Builder: Fix a crash when the widget is not found.
	
	* gtk/src/builder.ccg: get_widget_checked(): Prevent a crash if the widget 
	was not found by GtkBuilder.
	Bug #589267 (Alexander Shaduri)