[gtkmm] Glib::Object inheritance in Gtk::Object



Hello.

I restructured my application using Glib::RefPtr<> in several places and
now I sometimes get unreference() called with this = 0. I can reproduce
the problem quite easily.

I have a base class for object that can be annotated

class Annotated : public Glib::ObjectBase {
	...
};

I also have a UI component which allows the user to edit the notes:
NotesControllerUi. This controller takes a Glib::RefPtr<Annotated>.

Some of the annotated classes are Canvas (my own) and derive from both
Annotated and Gtk::VBox.

class Canvas : public Annotated, public Gtk::VBox {
...
};

But I also have Annotated object which are not of class Canvas and are
not even of subclasses of some Gtk::Widget. 

Everything works good as long as I don't edit a Canvas. The
CanvasControllerUi takes a Glib::RefPtr<Canvas> and creates an instance
of the NotesControllerUi. It is diplayed as child of the main controller
widget.
After I destroy the controller and continue to use my application,
sooner or later I'll get some warning from Glib or Gtk and then a crash:
unreference() has been called with this = 0.

I think one of the problems is that 

Gtk::Object : public Glib::Object

instead of

Gtk::Object : virtual public Glib::Object

Being so, I can't use virtual inheritance 

class Annotated : virtual public Glib::ObjectBase {
	...
};

has no effect.

What's your opinion? Is there any workaround?

I could use generic programming instead of multiple inheritance but I
already use many templates and my application takes ages and a lot of
memory to compile.
Also I'm sure this problem would present itself in other occasions.

Thanks,

Maurizio Umberto Puxeddu.





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