From: John L. <jla...@gm...> - 2005-12-16 05:13:10
|
> It was not easy to reproduce the situation in a small app but here it is: Ok so it stops as you say, on the line print(list:GetItemCount()); in function func(). I dug a little deeper and the problem is this. In modules/wxlua/wxlbind.cpp int LUACALL wxLua_lua_getTableFunc(lua_State *L) I added this printf statement, where init_xxx are the values by the same name used in the if() statement at the top. wxPrintf(wxT("wxLua_lua_getTableFunc '%s' pClass %d, userdata %d, lightuserdata %d, ttag %d, class_tag %d lua_State %d wxLuaStateRefData %d\n"), lua2wx(cpIndex).c_str(), (long)pClass, init_isuserdata, init_islightuserdata, init_ttag, init_class_tag, (long)L, (long)wxlState.GetRefData()); Here's the results #### the first print(list:GetItemCount()); that works wxLuaState::ttag 1 has metatable and is number 119 wxLuaState::ttag 1 has metatable and is number 119 wxLua_lua_getTableFunc 'GetItemCount' pClass -1218929716, userdata 1, lightuserdata 0, ttag 119, class_tag 119 lua_State 138563408 wxLuaStateRefData 136376552 # not really sure where these come from? but I suppose its ok wxLuaState::ttag 1 has metatable and is number 284 wxLuaState::ttag 1 has metatable and is number 119 #### the coroutine creates a new lua_State and we add ourselves to it (note the memory locations of the old and new (L1) lua_States) wxLuaInterpreter_newthread_handler new lua_State from a thread L=3D138563408 L1=3D138743720 #### we fail on trying to run wxLuaState::ttag(1) in wxLua_lua_getTableFunc (see ttag below) wxLuaState::ttag 1 wxLuaState::ttag 1 #### so the only thing wrong is ttag, we're got the new lua_State for the coroutine and we're still using the old wxLuaStateRefData (eg. the class that holds the wxLua data) wxLua_lua_getTableFunc '{unknown}' pClass -1218929716, userdata 1, lightuserdata 0, ttag 0, class_tag 119 lua_State 138743720 wxLuaStateRefData 136376552 The coroutine fails on lua_getmetatable() for the coroutine in this functio= n int wxLuaState::ttag(int index) { wxCHECK_MSG(Ok(), TLUA_NOTAG, wxT("Invalid wxLuaState")) lua_State* L =3D M_WXLSTATEDATA->m_lua_State; wxPrintf(wxT("wxLuaState::ttag %d"), index); int tag =3D TLUA_NOTAG; if (lua_getmetatable(L, index) !=3D 0) { wxPrintf(wxT(" has metatable")); lua_pushliteral(L, "tag"); lua_rawget(L, -2); if (lua_isnumber(L, -1)) { tag =3D (int) lua_tonumber(L, -1); wxPrintf(wxT(" and is number %d"), tag); } lua_pop(L, 2); } wxPrintf(wxT("\n")); return tag; } > frame =3D wx.wxFrame(wx.wxNull, -1, "App", > wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxDEFAULT_FRAME_STYLE)= ; > > list =3D wx.wxListCtrl(frame, -1, > wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxLC_SINGLE_SEL + > wx.wxLC_REPORT + wx.wxLC_AUTOARRANGE); > > -- works > print(list:GetItemCount()); > > function func() > > -- crashes > print(list:GetItemCount()); > > coroutine.yield(); > print(3); > end > > cr =3D coroutine.create(func); > > coroutine.resume(cr); > print(2); > coroutine.resume(cr); > > >I have added > >this code already, could you try again in a couple hours (for SF to > >sync it's cvs). > > > No sync yet, so I could not test the changes. I'm a little stumped, did this code of yours ever work with wxLua in any version? I'm not sure how to handle the failing lua_getmetatable in ttag for the coroutine since I thought that the new lua_State copied everything from the old one. Anyone have any ideas? I've committed by debugging printf statements to hel= p. Thanks, John Labenski |