mirror of
https://github.com/moparisthebest/minetest
synced 2024-12-23 08:08:47 -05:00
fix huge texture leak in tiledef
fix minor glitches too
This commit is contained in:
parent
3b684d306c
commit
5743ef4e64
57
src/tile.cpp
57
src/tile.cpp
@ -201,6 +201,13 @@ struct SourceAtlasPointer
|
|||||||
class SourceImageCache
|
class SourceImageCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
~SourceImageCache() {
|
||||||
|
for(std::map<std::string, video::IImage*>::iterator iter = m_images.begin();
|
||||||
|
iter != m_images.end(); iter++) {
|
||||||
|
iter->second->drop();
|
||||||
|
}
|
||||||
|
m_images.clear();
|
||||||
|
}
|
||||||
void insert(const std::string &name, video::IImage *img,
|
void insert(const std::string &name, video::IImage *img,
|
||||||
bool prefer_local, video::IVideoDriver *driver)
|
bool prefer_local, video::IVideoDriver *driver)
|
||||||
{
|
{
|
||||||
@ -209,23 +216,28 @@ public:
|
|||||||
std::map<std::string, video::IImage*>::iterator n;
|
std::map<std::string, video::IImage*>::iterator n;
|
||||||
n = m_images.find(name);
|
n = m_images.find(name);
|
||||||
if(n != m_images.end()){
|
if(n != m_images.end()){
|
||||||
video::IImage *oldimg = n->second;
|
if(n->second)
|
||||||
if(oldimg)
|
n->second->drop();
|
||||||
oldimg->drop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
video::IImage* toadd = img;
|
||||||
|
bool need_to_grab = true;
|
||||||
|
|
||||||
// Try to use local texture instead if asked to
|
// Try to use local texture instead if asked to
|
||||||
if(prefer_local){
|
if(prefer_local){
|
||||||
std::string path = getTexturePath(name.c_str());
|
std::string path = getTexturePath(name.c_str());
|
||||||
if(path != ""){
|
if(path != ""){
|
||||||
video::IImage *img2 = driver->createImageFromFile(path.c_str());
|
video::IImage *img2 = driver->createImageFromFile(path.c_str());
|
||||||
if(img2){
|
if(img2){
|
||||||
m_images[name] = img2;
|
toadd = img2;
|
||||||
return;
|
need_to_grab = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
img->grab();
|
|
||||||
m_images[name] = img;
|
if (need_to_grab)
|
||||||
|
toadd->grab();
|
||||||
|
m_images[name] = toadd;
|
||||||
}
|
}
|
||||||
video::IImage* get(const std::string &name)
|
video::IImage* get(const std::string &name)
|
||||||
{
|
{
|
||||||
@ -254,8 +266,7 @@ public:
|
|||||||
infostream<<"SourceImageCache::getOrLoad(): Loading path \""<<path
|
infostream<<"SourceImageCache::getOrLoad(): Loading path \""<<path
|
||||||
<<"\""<<std::endl;
|
<<"\""<<std::endl;
|
||||||
video::IImage *img = driver->createImageFromFile(path.c_str());
|
video::IImage *img = driver->createImageFromFile(path.c_str());
|
||||||
// Even if could not be loaded, put as NULL
|
|
||||||
//m_images[name] = img;
|
|
||||||
if(img){
|
if(img){
|
||||||
m_images[name] = img;
|
m_images[name] = img;
|
||||||
img->grab(); // Grab for caller
|
img->grab(); // Grab for caller
|
||||||
@ -274,7 +285,7 @@ class TextureSource : public IWritableTextureSource
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TextureSource(IrrlichtDevice *device);
|
TextureSource(IrrlichtDevice *device);
|
||||||
~TextureSource();
|
virtual ~TextureSource();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Example case:
|
Example case:
|
||||||
@ -454,6 +465,27 @@ TextureSource::TextureSource(IrrlichtDevice *device):
|
|||||||
|
|
||||||
TextureSource::~TextureSource()
|
TextureSource::~TextureSource()
|
||||||
{
|
{
|
||||||
|
video::IVideoDriver* driver = m_device->getVideoDriver();
|
||||||
|
|
||||||
|
unsigned int textures_before = driver->getTextureCount();
|
||||||
|
|
||||||
|
for (std::vector<SourceAtlasPointer>::iterator iter =
|
||||||
|
m_atlaspointer_cache.begin(); iter != m_atlaspointer_cache.end();
|
||||||
|
iter++)
|
||||||
|
{
|
||||||
|
video::ITexture *t = driver->getTexture(iter->name.c_str());
|
||||||
|
|
||||||
|
//cleanup texture
|
||||||
|
if (t)
|
||||||
|
driver->removeTexture(t);
|
||||||
|
|
||||||
|
//cleanup source image
|
||||||
|
iter->atlas_img->drop();
|
||||||
|
}
|
||||||
|
m_atlaspointer_cache.clear();
|
||||||
|
|
||||||
|
infostream << "~TextureSource() "<< textures_before << "/"
|
||||||
|
<< driver->getTextureCount() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 TextureSource::getTextureId(const std::string &name)
|
u32 TextureSource::getTextureId(const std::string &name)
|
||||||
@ -1205,7 +1237,6 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
|
|||||||
core::dimension2d<u32> dim = image->getDimension();
|
core::dimension2d<u32> dim = image->getDimension();
|
||||||
baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
|
baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
|
||||||
image->copyTo(baseimg);
|
image->copyTo(baseimg);
|
||||||
image->drop();
|
|
||||||
}
|
}
|
||||||
// Else blit on base.
|
// Else blit on base.
|
||||||
else
|
else
|
||||||
@ -1224,9 +1255,9 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
|
|||||||
video::SColor(255,255,255,255),
|
video::SColor(255,255,255,255),
|
||||||
NULL);*/
|
NULL);*/
|
||||||
blit_with_alpha(image, baseimg, pos_from, pos_to, dim);
|
blit_with_alpha(image, baseimg, pos_from, pos_to, dim);
|
||||||
// Drop image
|
|
||||||
image->drop();
|
|
||||||
}
|
}
|
||||||
|
//cleanup
|
||||||
|
image->drop();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user