View previous topic :: View next topic |
Author |
Message |
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Wed Apr 16, 2008 3:12 pm Post subject: |
|
|
I think i found the problem, in the constructor of gobject.ObjectG witch calls objectGSetDataFull("GObject",cast(void*)this); when multiple D objects get allocated for the same gtkStruct* then the pointer to the D object gets overwritten with the newest object, because the key used to store it is always "GObject". this in turn causes gobject.ObjectG.destroyNotify to be called by gtk and the old D object is removed as a GC root and it can be collected. |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sun Apr 20, 2008 11:34 am Post subject: |
|
|
I got the code i posted working by adding the following to the constructor of gtk.ComboBox:
Code: | @@ -132,6 +133,13 @@
*/
public this (GtkComboBox* gtkComboBox)
{
+ void* ptr = g_object_get_data(cast(GObject*)gtkComboBox, Str.toStringz("GObject"));
+ if ( ptr !is null )
+ {
+ this = cast(ComboBox)ptr;
+ return;
+ }
+
if(gtkComboBox is null)
{
this = null; |
To fix the issue all constructors should be modified like this. Or alternatively every function that returns a D object should check if there is an existing object in the gtk struct.
I'm still thinking about if it's better to do it in the constructor or in the functions. Does anybody have any thoughts about this? |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Thu Apr 24, 2008 3:57 pm Post subject: |
|
|
I implemented the constructor option in my working copy to do some tests. I ran into one segfault running the demos. witch was caused by two functions returning the same gtkstruct as different D objects.
This was gtk.widget.getDrawable and gtk.widget.getWindow both return a GdkWindow once wraped in it's base class gdk.Drawable and then as a gdk.Window. One option could be to remove/Depreciate gtk.Widget.getDrawable since only getWindow should be enough. |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Wed Apr 30, 2008 6:50 am Post subject: |
|
|
created ticket #33 to keep track of this bug. |
|
Back to top |
|
|
okibi
Joined: 04 Jan 2007 Posts: 170
|
Posted: Wed Jun 25, 2008 4:58 am Post subject: |
|
|
Mike, please see my update on your ticket. |
|
Back to top |
|
|
okibi
Joined: 04 Jan 2007 Posts: 170
|
Posted: Thu Jun 26, 2008 4:32 am Post subject: |
|
|
For anyone wanting to test a potential fix, please look at the comments on the ticket. |
|
Back to top |
|
|
|