[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: why crash?
- From: "l.jay Yuan" <pass86@...>
- Date: Mon, 20 Sep 2010 22:11:46 +0800
situation:
I am coding for a game project.
UI module using tolua++.
Logic module using luabind.
Them are using the same lua_State.
When UI event call lua callbacks, the callback call a export C function。
The code just like this
// Logic C code
luabind::object GetSameIDs() {
luabind::object ret = luabind::newtable(L);// L is the global lua_State
ret[1] = 123;
return ret;
}
// UI call C code
int top = lua_gettop(L);
lua_getglobal(L, strCallBackFuncName);
if (!lua_isfunction(L,-1)) {
lua_settop(L,top);
return
}
lua_pushlightuserdata(L , (void*)&e); // e is a C++ object, using for param
int error = lua_pcall(L, 1 , 1 , 0);
if (error) {
std::string errStr(lua_tostring(L, -1));
lua_pop(L, 0);
errStr = errStr + "\n";
OutputDebugString(errStr.c_str());
}
lua_tonumber(L,-1);
lua_settop(L,top);
// lua code
User = { Above100IDs = {} }
function OnClick()
local i = 1
local IDs = GetSameIDs()
for k,v in pairs(IDs) do
if v > 100 then
User.Above100IDs[i] = v -- crash here, crash code
ltable.c(425): gkey(mp)->value = key->value; gkey(mp)->tt = key->tt;
i = i + 1
end
end
end
If GetSameIDs() not call in UI event callback it is OK.
I find this: http://lua-users.org/lists/lua-l/2008-01/msg00669.html
I change the ltable.c(75) to "static volatile const Node dummynode_ = {"
And I rebuilded lua, tolua++.
The crash do not be fix.
OMG, I am in misery...
SOS...