aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2022-05-04 20:55:13 +0200
committersfan5 <sfan5@live.de>2022-05-14 18:33:42 +0200
commitb405985b807399d303933c004511e7bb9e5a540a (patch)
treee02ef82b86d1ddd8487f5c1de35aae06383d5da7
parent8b010c5a9feda44e4e21ecc0dd45aa01de14335a (diff)
downloadminetest-b405985b807399d303933c004511e7bb9e5a540a.tar.gz
minetest-b405985b807399d303933c004511e7bb9e5a540a.tar.bz2
minetest-b405985b807399d303933c004511e7bb9e5a540a.zip
guiScalingFilter: Fix most memory leaks (#12256)
Calls to the cache function ended up creating a new texture regardless whether the texture is already cached.
-rw-r--r--src/client/client.cpp2
-rw-r--r--src/client/guiscalingfilter.cpp12
2 files changed, 11 insertions, 3 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp
index 935a82653..0dd8a61d2 100644
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -334,6 +334,8 @@ Client::~Client()
// cleanup 3d model meshes on client shutdown
m_rendering_engine->cleanupMeshCache();
+ guiScalingCacheClear();
+
delete m_minimap;
m_minimap = nullptr;
diff --git a/src/client/guiscalingfilter.cpp b/src/client/guiscalingfilter.cpp
index 232219237..de122becf 100644
--- a/src/client/guiscalingfilter.cpp
+++ b/src/client/guiscalingfilter.cpp
@@ -43,6 +43,10 @@ void guiScalingCache(const io::path &key, video::IVideoDriver *driver, video::II
{
if (!g_settings->getBool("gui_scaling_filter"))
return;
+
+ if (g_imgCache.find(key) != g_imgCache.end())
+ return; // Already cached.
+
video::IImage *copied = driver->createImage(value->getColorFormat(),
value->getDimension());
value->copyTo(copied);
@@ -90,14 +94,16 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver,
io::path scalename = origname + "@guiScalingFilter:" + rectstr;
// Search for existing scaled texture.
- video::ITexture *scaled = g_txrCache[scalename];
+ auto it_txr = g_txrCache.find(scalename);
+ video::ITexture *scaled = (it_txr != g_txrCache.end()) ? it_txr->second : nullptr;
if (scaled)
return scaled;
// Try to find the texture converted to an image in the cache.
// If the image was not found, try to extract it from the texture.
- video::IImage* srcimg = g_imgCache[origname];
- if (srcimg == NULL) {
+ auto it_img = g_imgCache.find(origname);
+ video::IImage *srcimg = (it_img != g_imgCache.end()) ? it_img->second : nullptr;
+ if (!srcimg) {
if (!g_settings->getBool("gui_scaling_filter_txr2img"))
return src;
srcimg = driver->createImageFromData(src->getColorFormat(),