Included is a program that crashes with a segmentation fault. Possibly a
bug?
As soon as I leave the images out, it works OK. Also If I revert to
wxTreeCtrl, it works OK (including images).
I hope someone can help with this one?
Kind regards,
Dick Kniep
Well, this is quite weird. I would say it's a bug, but I'm not sure a
wxTreeListCtrl one. The reason: if you keep a reference to the image list
(e.g. self.il = imagelist) around, everything works. Well, sort of. If you
keep using AssignImageList, you get a segfault on exit, but it disappears
if you use SetImageList: so it seems that the imagelist object is deleted
when in fact it shouldn't.
Digging into the sources (gizmos.cpp), I tried to "Py_INCREF()" the
PyObject wrapper around the image list passed to (Set|Assign)ImageList, to
see if it changed something. And indeed the crash goes away... but I'm not
sure at all this is the right thing to do, as the same code for wxTreeCtrl
works even without such Py_INCREF() "calls". So, I really don't know where
to look now, and so I think I'll wait for Robin...
Anyway, as a workaround, just keep a reference to the image list and use
SetImageList instead of AssingImageList.
Included is a program that crashes with a segmentation fault. Possibly a
bug?
As soon as I leave the images out, it works OK. Also If I revert to
wxTreeCtrl, it works OK (including images).
I hope someone can help with this one?
Kind regards,
Dick Kniep
Well, this is quite weird. I would say it's a bug, but I'm not sure a
wxTreeListCtrl one. The reason: if you keep a reference to the image list
(e.g. self.il = imagelist) around, everything works. Well, sort of. If you
keep using AssignImageList, you get a segfault on exit, but it disappears
if you use SetImageList: so it seems that the imagelist object is deleted
when in fact it shouldn't.
Digging into the sources (gizmos.cpp), I tried to "Py_INCREF()" the
PyObject wrapper around the image list passed to (Set|Assign)ImageList, to
see if it changed something. And indeed the crash goes away... but I'm not
sure at all this is the right thing to do, as the same code for wxTreeCtrl
works even without such Py_INCREF() "calls". So, I really don't know where
to look now, and so I think I'll wait for Robin...
When you use AssignImageList then the tree takes ownership of the C++ image list object and will delete it when it is done with it. If you want to use the image list more than once then do *NOT* use AssignImageList. Instead you should use SetImagelist and then keep a reference to the image list yourself until you no longer need it.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
When you use AssignImageList then the tree takes ownership of the C++
image list object and will delete it when it is done with it. If you
want to use the image list more than once then do *NOT* use
AssignImageList. Instead you should use SetImagelist and then keep a
reference to the image list yourself until you no longer need it.
So, this pointed me in the right direction (I believe): in fact, the bug
is in gizmos.i, I think that in the various Assign*ImageList methods of
wxTreeListCtrl, there's a
I tried this, so I used SetImageList instead of AssignImageList, but I
still get the segmentation fault....
Hope someone can solve this?
Are you sure you kept a reference to the image list aswell? If so, Which
platform? And can you provide a small sample? (or just the differences wrt
the one you posted yesterday)
So, this pointed me in the right direction (I believe): in fact, the bug
is in gizmos.i, I think that in the various Assign*ImageList methods of
wxTreeListCtrl, there's a
missing, required for the above mechanism to work correctly (i.e. to avoid
that the C++ wxImageList is deallocated when it shouldn't).
Yep, you're right. Sorry about that, yet another example of why it would be nice if wxTreeListCtrl were able to derive from wxGenericTreeCtrl instead of just being copied from it.
I've made the fix above in CVS. If you see any other omissions please let me know.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Yep, you're right. Sorry about that, yet another example of why it
would be nice if wxTreeListCtrl were able to derive from
wxGenericTreeCtrl instead of just being copied from it.
I would have liked it too... But AFAIK, it wouldn't have been possible on
win, since by default the generic tree ctrl is not built (and I wasn't
able to inherit from the native one...). Anyway, most of the
implementation is on private methods or helper classes, which would have
had to be copied nevertheless...
I've made the fix above in CVS. If you see any other omissions please
let me know.