2013/7/30 Sebastian Götte <jaseg@...2974...>:
Hi, I'm currently having some problems allocating GObjects. I just added a class called SPPoint [0]. When I try to instantiate an object of that type (whether through SPObject/sp_object_child_added or manually from GDB using g_object_new does not matter), g_object_new returns an GObject* that contains a zero class: {g_type_instance = {g_class = 0x0}, ref_count = 0, qdata = 0x0} (this is not good as it breaks everything else about G_OBJECT). I was able to track down the problem to g_type_create_instance returning that when passed the new SPPoint type:
I think this is the problem:
static void sp_point_init(SPPoint *point){ new (point) SPPoint(); }
This will destroy parent initialization. Parent init functions which run before this one invoke the member constructors manually. In existing code, the constructor of SPObject is never called. The destructors are called manually in the dispose function. Instead of calling new, you have to construct each member separately.
Note that NRObject once contained a better solution to this problem, which automatically invoked the C++ constructor at instance init time. You can dig out nr-object.cpp and nr-object.h from source control and investigate. However, using it would require you to rewrite the init functions of all SPObjects.
Regards, Krzysztof