From: rubenwardy Date: Sat, 22 Dec 2018 07:46:41 +0000 (+0000) Subject: Android: Fix memory leak when displaying images in the mainmenu (#8011) X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ce4497224f6239a8e6c4aadfa7f593520602fa03;p=oweals%2Fminetest.git Android: Fix memory leak when displaying images in the mainmenu (#8011) --- diff --git a/src/guiEngine.cpp b/src/guiEngine.cpp index 2d1bd6d44..8661b1ca2 100644 --- a/src/guiEngine.cpp +++ b/src/guiEngine.cpp @@ -87,22 +87,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 } /******************************************************************************/