On Fri, Feb 13, 2009 at 5:43 AM, LPE <l...@f4-group.com> wrote:
> With wxLua 2.8.7.0 under Windows, this code produces a crash :
>
>    local proc = wx.wxProcess()
>    wx.wxExecute( "dir", wx.wxEXEC_ASYNC, proc )
>    proc = nil
>    collectgarbage( "collect" )
>
> Is there a way to prevent it?

Yes. The wxWidgets docs are a little cryptic, but I think they're
trying to say that you have to connect to the event to stop wxWidgets
from deleting it. See second paragraph.

http://docs.wxwidgets.org/stable/wx_wxprocess.html

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

USE_EVENT = 0

proc = wx.wxProcess()

if USE_EVENT then -- Use the wxProcessEvent to stop wxWidgets from deleting

proc:Connect(wx.wxEVT_END_PROCESS,
    function(event)
        print("Hello - the process is over and won't be deleted.")
        -- event:Skip(true) <-- will crash since wxWidgets will delete it too
        proc = nil
        collectgarbage( "collect" ) -- not necessary, but it tests the problem
    end)

else
   wxlua.ungcobject(proc) -- don't let Lua GC it, wxWidgets will do it
end

wx.wxExecute( "dir", wx.wxEXEC_ASYNC, proc )

if not USE_EVENT then
   proc = nil -- force GC to delete it
end

collectgarbage( "collect" )

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

I've shown two ways to do it, with and without events. I can't think
of any reasonable way that wxLua could detect that if you have
Connected to the wxEVT_END_PROCESS whether you are going to call
event:Skip(true/false) so there doesn't seem to be a way to make this
work more elegantly.

Hope this helps,
    John

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users

Reply via email to