diff --git a/src/luaapi.c b/src/luaapi.c index fac86cf..aac4934 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -254,7 +254,14 @@ static int game_addentity(lua_State *L) { if(lua_type(L, -1) == LUA_TSTRING) { strncpy(c.trimesh.name, lua_tostring(L, -1), sizeof(c.trimesh.name) - 1); } else { - c.trimesh.cache = *(struct TrimeshData**) luaL_checkudata(L, -1, "k3physics"); + struct TrimeshData *tmd = *(struct TrimeshData**) luaL_checkudata(L, -1, "k3physics"); + + struct ResManRes *res = resman_rev(tmd); + if(res) { + res->refs++; + } + + c.trimesh.cache = tmd; } } lua_pop(L, 1);