Re: Gtk::Widget::on_hide



On 18/11/2013 14:59, Alan Mazer wrote:
The G_OBJECT_GET_CLASS macro is probably dereferencing gobject_, e.g., replacing it with gobject_->class or some such...


Perhaps so. That would certainly explain the crash if 'gobject_' was NULL - but as I try to debug this issue things become even more confusing. Consider this sample program:-

        #include <gtkmm/main.h>
        #include <gtkmm/dialog.h>

        int main (int argc, char *argv[])
        {
            Gtk::Main    app (&argc, &argv);
Gtk::Dialog* mainWnd = new Gtk::Dialog ("Hello World", true, true);

            app.run( *mainWnd );

            delete mainWnd;
            return 0;
        }

The above example runs exactly as expected displaying a small, empty dialog window entitled "Hello World". Now consider this extended example which uses a class derived from Gtk::Dialog:-

        #include <gtkmm/main.h>
        #include <gtkmm/dialog.h>

        class MyDialog : public Gtk::Dialog {
        public:
MyDialog (const Glib::ustring& title, bool modal, bool use_separator);
        };

MyDialog::MyDialog (const Glib::ustring& title, bool modal, bool use_separator)
            : Gtk::Dialog (title, modal, use_separator)
        {
        }


        int main (int argc, char *argv[])
        {
            Gtk::Main    app (&argc, &argv);
            MyDialog* mainWnd = new MyDialog ("Hello World", true, true);
            app.run( *mainWnd );

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

When built using MSVC and gtkmm v2.24.2, the extended example consistently crashes at the line "delete mainWnd;". It either crashes in Gtk::Widget::on_hide() or slightly later, in Gtk::Widget::on_unrealize(). It's almost as if the C++ window object is going out of scope before gtkmm has finished its cleanup. Could this be a threading issue? I haven't created any threads (as you can see) so unless gtkmm or gtk+ created some I don't see how threading could be the problem. Or is there something obviously wrong which I'm failing to see??

John


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