Skip to content

Commit

Permalink
fix the crash bug when translating TMap to Lua table
Browse files Browse the repository at this point in the history
  • Loading branch information
rowechien committed Mar 20, 2020
1 parent 25ae911 commit 7ee4ad2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Plugins/UnLua/Source/UnLua/Private/BaseLib/LuaLib_Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,17 @@ static int32 TMap_ToTable(lua_State *L)
Keys->Get(i, Keys->ElementCache);
Keys->Inner->Read(L, Keys->ElementCache, true);

void *Value = Map->Find(Keys->ElementCache);
Map->ValueInterface->Read(L, Value, false);
void *ValueCache = (uint8*)Map->ElementCache + Map->MapLayout.ValueOffset;
Map->ValueInterface->Initialize(ValueCache);
bool bSuccess = Map->Find(Keys->ElementCache, ValueCache);
if (bSuccess)
{
Map->ValueInterface->Read(L, Map->ValueInterface->GetOffset() > 0 ? Map->ElementCache : ValueCache, true);
}
else
{
lua_pushnil(L);
}

lua_rawset(L, -3);
}
Expand Down

0 comments on commit 7ee4ad2

Please sign in to comment.