On Sat, Mar 8, 2008 at 5:28 AM, Eero Pajarre <[EMAIL PROTECTED]> wrote:
> On Fri, Mar 7, 2008 at 7:00 PM, Eero Pajarre <[EMAIL PROTECTED]> wrote:
>  > On Fri, Mar 7, 2008 at 6:45 PM, John Labenski <[EMAIL PROTECTED]> wrote:
>  >
>  >  >  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().
>  >
>  >  This sounds correct to me (based on wxwidgets code)
>
>  Actually after looking more at the code, I think that doing a
>  IncRef in Set operations is the better way, instead of this ungc-change.
...
>  As a related note, I think that the target should be, that IncRef/DecRef are
>  not be part of wxLua Lua-API. Incorrectly using DecRef will lead to program
>  crash, and I would rather have a "crash-proof-API".

I think this could work... so long as it's done in all the right
places, but we have to also make sure that we have removed them all
from Lua before the grid is deleted because the m_control member of
the editors will not be NULLed and the wxGridCellEditor will try to
delete it again. This is apparently has not been a problem in C++
since people either do not keep the editors around or they are members
of their own wxGrids and are deleted before the grid itself is
deleted.

>From my debugging I found that when the grid is destroyed we need to
have cleared all references in wxLua to renderers, editors, and
attributes by settings them to nil and running the garbage collector
or calling (ren:delete() to force it to be deleted immediately).
Simply calling IncRef() isn't enough, we have to make sure that we've
removed them from Lua and there is no way to detect the deletion in
any reasonable way with the given C++ api.

rend = wx.wxGridCellBoolRenderer()
rend:IncRef() -- could hide this in SetCellRenderer()
grid:SetCellRenderer(0, 1, rend)
rend = nil

edit = wx.wxGridCellBoolEditor()
edit:IncRef() -- could hide this in SetCellEditor()
grid:SetCellEditor(0, 1, edit)
edit = nil
collectgarbage("collect")

======================

ohhh, I may have found a found a way. It's ugly...

We can get at the m_control of the wxGridCellEditor class and NULL it this way.

#define wxGridCellEditorDummyFriend \
public: \
void NullControl() { m_control = NULL; }

When Lua wants to delete the wxGridCellEditor we catch it, search the
wxWindows (may be a slow process) for the pointer to the m_control, if
it's gone we call the above function to NULL it and DecRef() the
editor normally to delete it.

If the above works as planned then yes, we can simply do as you say
and call IncRef() from within any function that takes a
wxGridCellWorker derived class and requires IncRef() and it should all
work.

I will test the hack above in the next few days.

Regards,
    John

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users

Reply via email to