Fix memory leak of unicolor texture
Also try to hold them until the last moment, this may need some testing.
This commit is contained in:
parent
ef7201cf51
commit
b2cdc8c97e
@ -160,6 +160,7 @@ IrrDriver::~IrrDriver()
|
||||
}
|
||||
assert(m_device != NULL);
|
||||
|
||||
cleanUnicolorTextures();
|
||||
m_device->drop();
|
||||
m_device = NULL;
|
||||
m_modes.clear();
|
||||
@ -905,6 +906,7 @@ void IrrDriver::applyResolutionSettings()
|
||||
{
|
||||
Shaders::destroy();
|
||||
}
|
||||
cleanUnicolorTextures();
|
||||
initDevice();
|
||||
|
||||
font_manager = new FontManager();
|
||||
|
@ -59,6 +59,14 @@ static std::map<int, video::ITexture*> unicolor_cache;
|
||||
void resetTextureTable()
|
||||
{
|
||||
AlreadyTransformedTexture.clear();
|
||||
}
|
||||
|
||||
void cleanUnicolorTextures()
|
||||
{
|
||||
for (std::pair<const int, video::ITexture*>& uc : unicolor_cache)
|
||||
{
|
||||
uc.second->drop();
|
||||
}
|
||||
unicolor_cache.clear();
|
||||
}
|
||||
|
||||
@ -228,7 +236,6 @@ video::ITexture* getUnicolorTexture(const video::SColor &c)
|
||||
std::map<int, video::ITexture*>::iterator it = unicolor_cache.find(c.color);
|
||||
if (it != unicolor_cache.end())
|
||||
{
|
||||
it->second->grab();
|
||||
return it->second;
|
||||
}
|
||||
else
|
||||
@ -240,10 +247,12 @@ video::ITexture* getUnicolorTexture(const video::SColor &c)
|
||||
c.color
|
||||
};
|
||||
video::IImage *img = irr_driver->getVideoDriver()->createImageFromData(video::ECF_A8R8G8B8, core::dimension2d<u32>(2, 2), tmp);
|
||||
img->grab();
|
||||
std::stringstream name;
|
||||
name << "color" << c.color;
|
||||
video::ITexture* tex = irr_driver->getVideoDriver()->addTexture(name.str().c_str(), img);
|
||||
tex->grab();
|
||||
// Only let our map hold the unicolor texture
|
||||
irr_driver->getVideoDriver()->removeTexture(tex);
|
||||
unicolor_cache[c.color] = tex;
|
||||
img->drop();
|
||||
return tex;
|
||||
|
@ -26,6 +26,7 @@
|
||||
GLuint getTextureGLuint(irr::video::ITexture *tex);
|
||||
GLuint getDepthTexture(irr::video::ITexture *tex);
|
||||
void resetTextureTable();
|
||||
void cleanUnicolorTextures();
|
||||
void compressTexture(irr::video::ITexture *tex, bool srgb, bool premul_alpha = false);
|
||||
bool loadCompressedTexture(const std::string& compressed_tex);
|
||||
void saveCompressedTexture(const std::string& compressed_tex);
|
||||
|
Loading…
Reference in New Issue
Block a user