Unity2018.4.14 toLua+LuaTable导致UnityCrash

2019/12 17 17:12

id:41402

Lua中构建了一个表

local displayBuildIds = {}
local buildIds = config.City_Building
for i = 1,#buildIds do 
    table.insert(displayBuildIds, buildIds[i])
end 
Fire("UpdateCityGroupInfo",displayBuildIds)


C#中获得此表后:

LuaInterface.LuaTable buildIds = arg as LuaInterface.LuaTable;
var ids = buildIds.ToArray (); // 在此处Crash!



附:LuaTable.ToArray
public object[] ToArray()
{
int oldTop = luaState.LuaGetTop();
try
{
    luaState.Push(this);
    int len = luaState.LuaObjLen(-1);
    List<object> list = new List<object>(len + 1);
    int index = 1;
    object obj = null;
    while(index <= len)
    {
        luaState.LuaRawGetI(-1, index++);
        obj = luaState.ToVariant(-1);
        luaState.LuaPop(1);
        list.Add(obj);
    }                
    luaState.LuaSetTop(oldTop);
    return list.ToArray();
}
catch (Exception e)
{
    luaState.LuaSetTop(oldTop);
    throw e;
}
}

后改成传string解决此问题

--转载请注明: http://blog.coolcoding.cn/?p=854