aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-12-22 07:46:41 +0000
committerLoïc Blot <nerzhul@users.noreply.github.com>2018-12-22 08:46:41 +0100
commit0990ddb3bb96ab2e4c7a1ee44ed79c4218477949 (patch)
treedbb7bc72a63af9f10bbaaa9a5ccc5bcc18a72af2 /src/gui
parenta318bceb637809d605fe175ce86154e9c04494a6 (diff)
downloadminetest-0990ddb3bb96ab2e4c7a1ee44ed79c4218477949.tar.gz
minetest-0990ddb3bb96ab2e4c7a1ee44ed79c4218477949.tar.bz2
minetest-0990ddb3bb96ab2e4c7a1ee44ed79c4218477949.zip
Android: Fix memory leak when displaying images in the mainmenu (#8011)
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/guiEngine.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp
index a3ef1b9a6..a61847a04 100644
--- a/src/gui/guiEngine.cpp
+++ b/src/gui/guiEngine.cpp
@@ -70,22 +70,30 @@ MenuTextureSource::~MenuTextureSource()
/******************************************************************************/
video::ITexture *MenuTextureSource::getTexture(const std::string &name, u32 *id)
{
- if(id)
+ if (id)
*id = 0;
- if(name.empty())
+
+ if (name.empty())
return NULL;
+
m_to_delete.insert(name);
#ifdef __ANDROID__
- video::IImage *image = m_driver->createImageFromFile(name.c_str());
- if (image) {
- image = Align2Npot2(image, m_driver);
- video::ITexture* retval = m_driver->addTexture(name.c_str(), image);
- image->drop();
+ video::ITexture *retval = m_driver->findTexture(name.c_str());
+ if (retval)
return retval;
- }
-#endif
+
+ video::IImage *image = m_driver->createImageFromFile(name.c_str());
+ if (!image)
+ return NULL;
+
+ image = Align2Npot2(image, m_driver);
+ retval = m_driver->addTexture(name.c_str(), image);
+ image->drop();
+ return retval;
+#else
return m_driver->getTexture(name.c_str());
+#endif
}
/******************************************************************************/