From 1c165601c263e8b07ef2bb38d7c56358744c6b34 Mon Sep 17 00:00:00 2001 From: mid <> Date: Mon, 20 Jan 2025 10:52:26 +0200 Subject: [PATCH] Add trimesh to reference count --- src/luaapi.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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);