Fix ref counting crash

This commit is contained in:
Marianne Gagnon
2014-09-18 19:16:36 -04:00
committed by Vincent Lejeune
parent 4b2b56035f
commit 000b427f58

View File

@@ -169,17 +169,31 @@ void saveCompressedTexture(const std::string& compressed_tex)
static unsigned colorcount = 0;
std::map<int, video::ITexture*> unicolor_cache;
video::ITexture* getUnicolorTexture(const video::SColor &c)
{
unsigned tmp[4] = {
c.color,
c.color,
c.color,
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;
return irr_driver->getVideoDriver()->addTexture(name.str().c_str(), img);
std::map<int, video::ITexture*>::iterator it = unicolor_cache.find(c.color);
if (it != unicolor_cache.end())
{
it->second->grab();
return it->second;
}
else
{
unsigned tmp[4] = {
c.color,
c.color,
c.color,
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);
unicolor_cache[c.color] = tex;
img->drop();
return tex;
}
}