this is a test case, run it, and click the cell, crash
test.lua:
require( "iuplua" )
require( "iupluacontrols" )
local mat
function task()
mat = iup.matrix {numcol=5, numlin=3,numcol_visible=5,
numlin_visible=3, widthdef=34}
mat:setcell(0,0,"Inflation11")
mat:setcell(1,0,"Medicine")
mat.click_cb=function() end
end
coroutine.resume(coroutine.create(task))
collectgarbage()
collectgarbage()
dlg = iup.dialog{iup.vbox{mat; margin="10x10"}}
dlg:showxy(iup.CENTER, iup.CENTER)
if (iup.MainLoopLevel()==0) then
iup.MainLoop()
end
----------------------------------
I patch the iuplua.c, the function iuplua_plugstate patch should be ok , it
hold the thread state ref, but I am not sure it where to free the Luastate ref,
I use il_destroy_cb, this maybe not correct.
在 2012-4-27,21:20, Antonio Scuri 写道:
> Hi,
>
> I never used Lua coroutines, so don’t know if this is going to solve your
> problem or not. But I would like to help you.
>
> Can you build a very small example that demonstrates the problem?
>
> In the solution you propose, the stored context reference will be used
> anywhere else?
>
> Thanks,
> Scuri
>
> From: zcs_chenxiao [mailto:[email protected]]
> Sent: sexta-feira, 27 de abril de 2012 03:00
> To: IUP discussion list
> Subject: [Iup-users] crash when using iuplua with lua coroutine, and a temp
> patch
>
> I using lua coroutine , and in the lua thread , I create iup controls, then
> when the lua thread end and gc, game crash.
>
> the patch can avoid the crash , but I can't sure where to free the lua ref.
>
> change the iuplua.c
>
> void iuplua_plugstate(lua_State *L, Ihandle *ih)
> {
> int ref;
> lua_pushthread(L);
> ref=lua_ref(L,LUA_REGISTRYINDEX); /*keep ref for L, L maybe a
> thread*/
> IupSetAttribute(ih, "_IUPLUA_STATE_CONTEXT",(char *) L);
> IupSetAttribute(ih, "_IUPLUA_STATE_CONTEXT_REF",(char *) ref);
> printf("iuplua_plugstate %d\n",ref);
> }
>
> ???? maybe free the ref on this function 'il_destroy_cb' ?????
> static int il_destroy_cb(Ihandle* ih)
> {
> /* called from IupDestroy. */
> char* sref = IupGetAttribute(ih, "_IUPLUA_WIDGET_TABLE_REF");
> if (sref)
> {
> lua_State *L = iuplua_getstate(ih);
> int ref = atoi(sref);
>
> /* removes the ihandle reference in the lua table */
> /* object.handle = nil */
> lua_rawgeti(L, LUA_REGISTRYINDEX, ref); /* push object */
> lua_pushstring(L, "handle");
> lua_pushnil(L);
> lua_settable(L, -3);
> lua_pop(L,1);
>
> /* removes the association of the ihandle with the lua table */
> luaL_unref(L, LUA_REGISTRYINDEX, ref); /* this is the complement of
> SetWidget */
> IupSetAttribute(ih, "_IUPLUA_WIDGET_TABLE_REF", NULL);
> IupSetCallback(ih, "LDESTROY_CB", NULL);
> }
> sref = IupGetAttribute(ih, "_IUPLUA_STATE_CONTEXT_REF");
> if (sref)
> {
> lua_State *L = iuplua_getstate(ih);
> int ref=(int)sref;
> lua_unref(L,ref);
> IupSetAttribute(ih, "_IUPLUA_STATE_CONTEXT_REF", NULL);
> printf("il_destroy_cb %d\n",ref);
> }
>
> return IUP_DEFAULT;
> }
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats.
> http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
> Iup-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/iup-users
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Iup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/iup-users