|
From: John L. <jla...@gm...> - 2007-08-03 02:03:08
|
I have checked in a fix for it. For reference it can be duplicated
with the code below. It was a tough problem to track down and it is
still not clear to me why it happens on with wxPostEvent with the
constraints that you have to Connect to the event that was posted and
not for other cases I tried. The scenario below follows from tracking
the memory of objects pushed into Lua.
The problem was with the event pushed into Lua for the
wxLuaCallback::CallFunction() event handler. Since we didn't create
it, actually it's on the C++ stack not the heap, it gets deleted when
it goes out of scope in C++ and the memory for it can be reused. Since
Lua has an incremental garbage collector it doesn't call the __gc
method soon enough to clear the key in the object table. Therefore a
new object that by chance was created with the same memory address
would be found in the object table and the old userdata was pushed
into Lua as whatever type it was.
Thanks for reporting it.
John Labenski
=============================
frame = nil
function HandleEvents(event)
local name = event:GetEventObject():DynamicCast("wxWindow"):GetName()
frame:SetStatusText(string.format("%s - selected item %d '%s'",
name, event:GetSelection(), event:GetString()), 0)
local e = wx.wxCommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, 10)
wx.wxPostEvent(frame, e)
end
function main()
frame = wx.wxFrame(wx.NULL, wx.wxID_ANY, "wxLua Choices",
wx.wxDefaultPosition, wx.wxSize(550, 350))
frame:CreateStatusBar(1)
frame:Connect(wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event)
print("hi") end)
local notebook = wx.wxNotebook(frame, wx.wxID_ANY,
wx.wxDefaultPosition, wx.wxSize(410, 300))
--wx.wxNB_BOTTOM)
notebook:AddPage(wx.wxPanel(notebook, wx.wxID_ANY), "Page1")
notebook:AddPage(wx.wxPanel(notebook, wx.wxID_ANY), "Page2")
notebook:AddPage(wx.wxPanel(notebook, wx.wxID_ANY), "Page3")
frame:Connect(wx.wxID_ANY, wx.wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
HandleEvents)
frame:Show(true)
end
main()
=========================
|