FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Memory bug in gtkD?
Goto page Previous  1, 2
 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Wed Apr 16, 2008 3:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sun Apr 20, 2008 11:34 am    Post subject: Reply with quote

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
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Thu Apr 24, 2008 3:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Wed Apr 30, 2008 6:50 am    Post subject: Reply with quote

created ticket #33 to keep track of this bug.
Back to top
View user's profile Send private message
okibi



Joined: 04 Jan 2007
Posts: 170

PostPosted: Wed Jun 25, 2008 4:58 am    Post subject: Reply with quote

Mike, please see my update on your ticket.
Back to top
View user's profile Send private message
okibi



Joined: 04 Jan 2007
Posts: 170

PostPosted: Thu Jun 26, 2008 4:32 am    Post subject: Reply with quote

For anyone wanting to test a potential fix, please look at the comments on the ticket.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group