Re: Is gtkmm deleting stuff it shouldn't be deleting ??



Hi Murray, I've made great progress with this today and I've discovered what the problem is - though not yet where to fix it. I'm sure anyway that you'll be much better informed about where to implement a fix. The main thing is that the problem had nothing to do with any 'this' pointer anomaly. That was a complete red herring. Here's my test code again:-

        #include "gtkmm/main.h"
        #include "gtkmm/window.h"

        int main (int argc, char *argv[])
        {
          Gtk::Main    app (&argc, &argv);
          Gtk::Window*  mainWnd = new Gtk::Window;

                mainWnd->set_title("Hello World!");

                app.run( *mainWnd );

                delete mainWnd;  // <--- crashes here !
                return 0;
        }

'app.run( *mainWnd );' displays an empty gtkmm window with the title "Hello World". Allowing the window to close normally will call 'gtk_widget_destroy()' which, in turn, calls 'gtk_object_destroy()' and ultimately, 'g_object_run_dispose()'. As expected, the gtkmm window disappears from my screen. Now we reach this line:-

                delete mainWnd;  // <--- crashes here !

The above line invokes the d'tor for Gtk::Window. The d'tor calls 'Gtk::Window::destroy_()' which then calls 'Gtk::Window::_destroy_c_instance()'. Note that 'Gtk::Window::_destroy_c_instance()' contains some warnings about ensuring that 'C' and C++ objects get destroyed in the correct sequence. Once inside 'Gtk::Window::_destroy_c_instance()' we hit this code:-

        if (!gobject_disposed_)
        {
              //Windows can not be unrefed. They are "self-owning".
              gtk_object_destroy(object);
        }

and bingo! We call 'gtk_object_destroy()' all over again on an object that's already been destroyed! The crash actually occurs in 'g_object_run_dispose()' at this line:-

        G_OBJECT_GET_CLASS (object)->dispose (object);

Effectively, we're trying to get the class of an object that GTK+ just destroyed for us. Hope you can make sense of all that!

John


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