I'm trying to get goocanvasmm working from a C++ program. From a couple
of places I combined code snippets and got the program to draw.
However, on program termination, a segfault appears. I'm not a normal C++ user,
and as such, the gdb messages are somewhat cryptic to me.
Here's the code. It creates a window, and draws a 200x200 pixel yellow square in it:
#include <gtkmm.h>
#include <goocanvasmm.h>
#include <iostream>
#define UI_FILE "gtk_foobar.ui"
int
main (int argc, char *argv[]) {
Gtk::Main kit(argc, argv);
//Load the Glade file and instiate its widgets:
Glib::RefPtr<Gtk::Builder> builder;
try {
builder = Gtk::Builder::create_from_file(UI_FILE);
}
catch (const Glib::FileError & ex) {
std::cerr << ex.what() << std::endl;
return 1;
}
Gtk::Window *main_win = 0;
builder->get_widget("main_window", main_win);
Goocanvas::Canvas canvas;
main_win->add(canvas);
auto root = (canvas).get_root_item();
auto rect = Goocanvas::Rect::create(100, 100, 200, 200);
rect->property_stroke_color() = "yellow";
rect->property_line_width() = 3;
root->add_child(rect);
main_win->show_all();
if (main_win) {
kit.run(*main_win);
}
return 0;
}
the run-time error message (shown on program termination):
Program has been terminated receiving signal 11 (Segmentation fault)
and the gdb backtrace:
#0 0x00007ffff5ae7d6c in free () at /lib64/libc.so.6
#1 0x00007ffff5a97736 in __cxa_finalize () at /lib64/libc.so.6
#2 0x00007ffff7d22946 in __do_global_dtors_aux () at /usr/lib64/libgoocanvasmm-2.0.so.6
#3 0x00007ffff7ffd060 in _rtld_local () at /lib64/ld-linux-x86-64.so.2
#4 0x0000000000000000 in ()
If I'm not mistaken, this seems to indicate a problem with the destructors in
libgoocanvasmm.
Edit: I realized (a little late) that, to run the application, it's also necessary to have the UIFILE. Here it is ("gtk_foobar.ui"):
<?xml version="1.0"?>
<interface>
<!-- interface-naming-policy project-wide -->
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="main_window">
<property name="visible">True</property>
<property name="title" translatable="yes">Hello World!</property>
<property name="default_width">500</property>
<property name="default_height">400</property>
<child>
<placeholder/>
</child>
</object>
</interface>
To make things easier, this link will download the complete autotools project.