mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 08:03:45 +01:00
guiScalingFilter: Fix most memory leaks (#12256)
Calls to the cache function ended up creating a new texture regardless whether the texture is already cached.
This commit is contained in:
parent
0704ca0550
commit
3ce5a68cd1
@ -334,6 +334,8 @@ Client::~Client()
|
|||||||
// cleanup 3d model meshes on client shutdown
|
// cleanup 3d model meshes on client shutdown
|
||||||
m_rendering_engine->cleanupMeshCache();
|
m_rendering_engine->cleanupMeshCache();
|
||||||
|
|
||||||
|
guiScalingCacheClear();
|
||||||
|
|
||||||
delete m_minimap;
|
delete m_minimap;
|
||||||
m_minimap = nullptr;
|
m_minimap = nullptr;
|
||||||
|
|
||||||
|
@ -43,6 +43,10 @@ void guiScalingCache(const io::path &key, video::IVideoDriver *driver, video::II
|
|||||||
{
|
{
|
||||||
if (!g_settings->getBool("gui_scaling_filter"))
|
if (!g_settings->getBool("gui_scaling_filter"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (g_imgCache.find(key) != g_imgCache.end())
|
||||||
|
return; // Already cached.
|
||||||
|
|
||||||
video::IImage *copied = driver->createImage(value->getColorFormat(),
|
video::IImage *copied = driver->createImage(value->getColorFormat(),
|
||||||
value->getDimension());
|
value->getDimension());
|
||||||
value->copyTo(copied);
|
value->copyTo(copied);
|
||||||
@ -90,14 +94,16 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver,
|
|||||||
io::path scalename = origname + "@guiScalingFilter:" + rectstr;
|
io::path scalename = origname + "@guiScalingFilter:" + rectstr;
|
||||||
|
|
||||||
// Search for existing scaled texture.
|
// 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)
|
if (scaled)
|
||||||
return scaled;
|
return scaled;
|
||||||
|
|
||||||
// Try to find the texture converted to an image in the cache.
|
// 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.
|
// If the image was not found, try to extract it from the texture.
|
||||||
video::IImage* srcimg = g_imgCache[origname];
|
auto it_img = g_imgCache.find(origname);
|
||||||
if (srcimg == NULL) {
|
video::IImage *srcimg = (it_img != g_imgCache.end()) ? it_img->second : nullptr;
|
||||||
|
if (!srcimg) {
|
||||||
if (!g_settings->getBool("gui_scaling_filter_txr2img"))
|
if (!g_settings->getBool("gui_scaling_filter_txr2img"))
|
||||||
return src;
|
return src;
|
||||||
srcimg = driver->createImageFromData(src->getColorFormat(),
|
srcimg = driver->createImageFromData(src->getColorFormat(),
|
||||||
|
Loading…
Reference in New Issue
Block a user