From 4c454c4147a9bbb4c0ae50f21c7970c3a1215110 Mon Sep 17 00:00:00 2001 From: Sarrum Date: Sat, 10 Oct 2020 05:30:55 +0300 Subject: [PATCH 1/4] Fix engineGetModelTextures memory leak --- .../deathmatch/logic/luadefs/CLuaEngineDefs.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp index b8d8c2b41d5..7aabb518a38 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp @@ -1126,11 +1126,24 @@ int CLuaEngineDefs::EngineGetModelTextures(lua_State* luaVM) if (argStream.HasErrors()) return luaL_error(luaVM, argStream.GetFullErrorMessage()); + CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM); + CResource* pParentResource = pLuaMain ? pLuaMain->GetResource() : NULL; + + if (!pParentResource) + { + lua_pushnil(luaVM); + return 1; + } + lua_newtable(luaVM); for (const auto& pair : textureList) { CClientTexture* pTexture = g_pClientGame->GetManager()->GetRenderElementManager()->CreateTexture("", &std::get<1>(pair), RDEFAULT, RDEFAULT, RDEFAULT, RFORMAT_UNKNOWN, TADDRESS_WRAP); + if (pTexture) + { + pTexture->SetParent(pParentResource->GetResourceDynamicEntity()); + } lua_pushstring(luaVM, std::get<0>(pair).c_str()); lua_pushelement(luaVM, pTexture); lua_settable(luaVM, -3); From f6fac8809d72c747ccbc4b640c134c0b7b1a316f Mon Sep 17 00:00:00 2001 From: Qais Patankar Date: Sat, 10 Oct 2020 04:40:41 +0100 Subject: [PATCH 2/4] Add Sarrum to credits --- Client/core/CCredits.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Client/core/CCredits.cpp b/Client/core/CCredits.cpp index 09bbe1ed625..8bf505ca7f6 100644 --- a/Client/core/CCredits.cpp +++ b/Client/core/CCredits.cpp @@ -171,6 +171,7 @@ CCredits::CCredits() "pentaflops\n" "knitz12\n" "ApeLsiN4eG\n" + "theSarrum\n" "\n" "\n"; From ebaa2e105f3a9c5811eade3288fd688b7b2c20b7 Mon Sep 17 00:00:00 2001 From: Sarrum Date: Sat, 10 Oct 2020 18:07:08 +0300 Subject: [PATCH 3/4] Remove unnecessary check --- Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp index 7aabb518a38..758cb2c0bae 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp @@ -1129,12 +1129,6 @@ int CLuaEngineDefs::EngineGetModelTextures(lua_State* luaVM) CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM); CResource* pParentResource = pLuaMain ? pLuaMain->GetResource() : NULL; - if (!pParentResource) - { - lua_pushnil(luaVM); - return 1; - } - lua_newtable(luaVM); for (const auto& pair : textureList) { From 5af838152d5c58bc8e0c81103c01821fbe6d967a Mon Sep 17 00:00:00 2001 From: Sarrum Date: Sat, 10 Oct 2020 19:28:39 +0300 Subject: [PATCH 4/4] Add suggested change Co-authored-by: Qais Patankar --- Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp index 758cb2c0bae..99e80011a99 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp @@ -1127,7 +1127,7 @@ int CLuaEngineDefs::EngineGetModelTextures(lua_State* luaVM) return luaL_error(luaVM, argStream.GetFullErrorMessage()); CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM); - CResource* pParentResource = pLuaMain ? pLuaMain->GetResource() : NULL; + CResource* pParentResource = pLuaMain->GetResource(); lua_newtable(luaVM); for (const auto& pair : textureList)