Skip to content

Commit fcfd53a

Browse files
sapiersapier
sapier
authored and
sapier
committed
Don't keep temporary images in RAM
1 parent 334ec4b commit fcfd53a

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

src/tile.cpp

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,13 @@ struct TextureInfo
164164
{
165165
std::string name;
166166
video::ITexture *texture;
167-
video::IImage *img; // The source image
168167

169168
TextureInfo(
170169
const std::string &name_,
171-
video::ITexture *texture_=NULL,
172-
video::IImage *img_=NULL
170+
video::ITexture *texture_=NULL
173171
):
174172
name(name_),
175-
texture(texture_),
176-
img(img_)
173+
texture(texture_)
177174
{
178175
}
179176
};
@@ -460,10 +457,6 @@ TextureSource::~TextureSource()
460457
//cleanup texture
461458
if (iter->texture)
462459
driver->removeTexture(iter->texture);
463-
464-
//cleanup source image
465-
if (iter->img)
466-
iter->img->drop();
467460
}
468461
m_textureinfo_cache.clear();
469462

@@ -666,23 +659,17 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
666659

667660
TextureInfo *ti = &m_textureinfo_cache[base_image_id];
668661

669-
if(ti->img == NULL)
662+
if(ti->texture == NULL)
670663
{
671-
infostream<<"getTextureIdDirect(): WARNING: NULL image in "
664+
infostream<<"getTextureIdDirect(): WARNING: NULL Texture in "
672665
<<"cache: \""<<base_image_name<<"\""
673666
<<std::endl;
674667
}
675668
else
676669
{
677-
core::dimension2d<u32> dim = ti->img->getDimension();
678-
679-
baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
670+
core::dimension2d<u32> dim = ti->texture->getSize();
680671

681-
ti->img->copyTo(
682-
baseimg, // target
683-
v2s32(0,0), // position in target
684-
core::rect<s32>(v2s32(0,0), dim) // from
685-
);
672+
baseimg = driver->createImage(ti->texture,v2s32(0,0), dim);
686673

687674
/*infostream<<"getTextureIdDirect(): Loaded \""
688675
<<base_image_name<<"\" from image cache"
@@ -717,6 +704,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
717704
{
718705
// Create texture from resulting image
719706
t = driver->addTexture(name.c_str(), baseimg);
707+
baseimg->drop();
720708
}
721709

722710
/*
@@ -726,7 +714,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
726714
JMutexAutoLock lock(m_textureinfo_cache_mutex);
727715

728716
u32 id = m_textureinfo_cache.size();
729-
TextureInfo ti(name, t, baseimg);
717+
TextureInfo ti(name, t);
730718
m_textureinfo_cache.push_back(ti);
731719
m_name_to_id[name] = id;
732720

@@ -809,12 +797,13 @@ void TextureSource::rebuildImagesAndTextures()
809797
video::IImage *img = generateImageFromScratch(ti->name);
810798
// Create texture from resulting image
811799
video::ITexture *t = NULL;
812-
if(img)
800+
if(img) {
813801
t = driver->addTexture(ti->name.c_str(), img);
802+
img->drop();
803+
}
814804
video::ITexture *t_old = ti->texture;
815805
// Replace texture
816806
ti->texture = t;
817-
ti->img = img;
818807

819808
if (t_old != 0)
820809
m_texture_trash.push_back(t_old);
@@ -975,7 +964,7 @@ bool TextureSource::generateImage(std::string part_of_name, video::IImage *& bas
975964

976965
if (image == NULL) {
977966
if (part_of_name != "") {
978-
if (part_of_name.find("_normal.png") == std::string::npos){
967+
if (part_of_name.find("_normal.png") == std::string::npos){
979968
errorstream<<"generateImage(): Could not load image \""
980969
<<part_of_name<<"\""<<" while building texture"<<std::endl;
981970
errorstream<<"generateImage(): Creating a dummy"

0 commit comments

Comments
 (0)