On Fri, Mar 7, 2008 at 9:32 AM, Eero Pajarre <[EMAIL PROTECTED]> wrote: > > I got rid of the previous crash, but still there is something causing > > memory corruption according to the "free"-function with debugging > > builds. My code calls Lua incremental GC during execution, so > > I guess I maybe more sensitive for these, but this is of course > > good so that the bugs don't stay hidden. > > > > SetColAttr and related functions seem also be part of the problem, > and IncRef makes the symptoms less, but these functions also > contain a call to wxluaO_undeletegcobject so I guess I should need > to understand more of wxLua internals...
Heh, hopefully it won't be too difficult. > Also using IncRef here is propably not ok in case the same Attribute > set is used on multiple colums/rows, although a minor memory leak > is not the worst thing now. > > (I have been using IncRef so that the wxWidget object does > not get destroyed when the Lua object is garbage collected, after the > wxWidget-object has been given to > the custody of some other object) After looking into it a little more, I think the best solution is to use the %ungc tag in the interface file so that we have: wxGrid::SetCellEditor(int row, int col, %ungc wxGridCellEditor *editor) This means that Lua will not try to delete the editor and it's up to the wxGrid (actually wxGridCellAttr) to delete it by calling DecRef(). You can retrieve it using : wxGridCellEditor* GetCellEditor(int row, int col) and the returned wxGridCellEditor will not be garbage collected by Lua. This is not perfectly ideal in that I would think this code should be all you need. edit = wx.wxGridCellBoolEditor(...) -- same for wxGridCellXXXRenderer -- ref count for edit == 1 edit:IncRef() -- ref count for edit == 2 grid:SetCellEditor(1,2,edit) -- ref count for edit == 2 *** If you have the code below it works great, without it the program crashes in the way I described before. When the wxGrid is destroyed, it destroys the children windows including the m_control of the wxGridCellEditor and then later Lua will delete the wxGridCellEditor (which is completely valid since it has a ref count of 1), but the m_control pointer is not NULL, but points to nothing since it was deleted, and the wxGridCellEditor tries to delete it again. edit = nil collectgarbage("collect") -- ref count for edit == 1 and the wxGrid will delete it A vaguely similar scenario happens for Renderers and Attributes. Regards, John ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ wxlua-users mailing list wxlua-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wxlua-users