1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-25 17:53:47 +00:00

Fix rare texture loading problems introduced in 8bd40be8aa and f0d580d873.

This commit is contained in:
fgenesis 2016-03-13 01:37:43 +01:00
parent 198f0353d5
commit 62c949f640
5 changed files with 29 additions and 32 deletions

View file

@ -4429,7 +4429,7 @@ std::string Core::getTextureLoadName(const std::string &texture)
return loadName;
}
std::pair<CountedPtr<Texture>, TextureLoadResult> Core::doTextureAdd(const std::string &texture, const std::string &loadName, std::string internalTextureName)
CountedPtr<Texture> Core::doTextureAdd(const std::string &texture, const std::string &loadName, std::string internalTextureName)
{
if (texture.empty() || !ISPATHROOT(texture))
{
@ -4448,35 +4448,28 @@ std::pair<CountedPtr<Texture>, TextureLoadResult> Core::doTextureAdd(const std::
stringToLowerUserData(internalTextureName);
CountedPtr<Texture> t = core->findTexture(internalTextureName);
if (t)
return std::make_pair(t, TEX_SUCCESS);
return t;
t = new Texture;
t->name = internalTextureName;
unsigned res = TEX_FAILED;
if(t->load(loadName))
res |= (TEX_LOADED | TEX_SUCCESS);
else
if(!t->load(loadName))
{
t->width = 64;
t->height = 64;
}
return std::make_pair(t, (TextureLoadResult)res);
return t;
}
CountedPtr<Texture> Core::addTexture(const std::string &textureName, TextureLoadResult *pLoadResult /* = 0 */)
CountedPtr<Texture> Core::addTexture(const std::string &textureName)
{
BBGE_PROF(Core_addTexture);
if (textureName.empty())
{
if(pLoadResult)
*pLoadResult = TEX_FAILED;
return NULL;
}
std::pair<CountedPtr<Texture>, TextureLoadResult> texResult;
CountedPtr<Texture> ptex;
std::string texture = textureName;
stringToLowerUserData(texture);
std::string internalTextureName = texture;
@ -4493,33 +4486,31 @@ CountedPtr<Texture> Core::addTexture(const std::string &textureName, TextureLoad
std::string ln = loadName;
texture = secondaryTexturePath + texture;
loadName = texture;
texResult = doTextureAdd(texture, loadName, internalTextureName);
if (!texResult.second)
texResult = doTextureAdd(t, ln, internalTextureName);
ptex = doTextureAdd(texture, loadName, internalTextureName);
if (!ptex || ptex->getLoadResult() == TEX_FAILED)
ptex = doTextureAdd(t, ln, internalTextureName);
}
else
texResult = doTextureAdd(texture, loadName, internalTextureName);
ptex = doTextureAdd(texture, loadName, internalTextureName);
addTexture(texResult.first.content());
addTexture(ptex.content());
if(debugLogTextures)
{
if (texResult.second & TEX_LOADED)
if (ptex)
{
std::ostringstream os;
os << "LOADED TEXTURE FROM DISK: [" << internalTextureName << "] idx: " << resources.size()-1;
debugLog(os.str());
}
else if(!(texResult.second & TEX_SUCCESS))
else if(ptex->getLoadResult() != TEX_SUCCESS)
{
std::ostringstream os;
os << "FAILED TO LOAD TEXTURE: [" << internalTextureName << "] idx: " << resources.size()-1;
debugLog(os.str());
}
}
if(pLoadResult)
*pLoadResult = texResult.second;
return texResult.first;
return ptex;
}
void Core::addRenderObject(RenderObject *o, int layer)

View file

@ -1023,7 +1023,7 @@ public:
void removeTexture(Texture *res);
void clearResources();
CountedPtr<Texture> addTexture(const std::string &texture, TextureLoadResult *pLoadResult = 0);
CountedPtr<Texture> addTexture(const std::string &texture);
PostProcessingFX postProcessingFx;
@ -1328,7 +1328,7 @@ protected:
virtual void onReloadResources();
std::pair<CountedPtr<Texture>, TextureLoadResult> doTextureAdd(const std::string &texture, const std::string &name, std::string internalTextureName);
CountedPtr<Texture> doTextureAdd(const std::string &texture, const std::string &name, std::string internalTextureName);
void deleteRenderObjectMemory(RenderObject *r);
bool _hasFocus;

View file

@ -1365,13 +1365,12 @@ bool RenderObject::setTexture(const std::string &n)
if (name.empty())
return false;
if(texture && name == texture->name)
if(texture && texture->getLoadResult() == TEX_SUCCESS && name == texture->name)
return true; // no texture change
TextureLoadResult res = TEX_FAILED;
CountedPtr<Texture> tex = core->addTexture(name, &res);
CountedPtr<Texture> tex = core->addTexture(name);
setTexturePointer(tex);
return !!tex && res != TEX_FAILED;
return tex && tex->getLoadResult() == TEX_SUCCESS;
}
float RenderObject::getSortDepth()

View file

@ -69,6 +69,7 @@ Texture::Texture()
repeating = false;
pngSetStandardOrientation(0);
ow = oh = -1;
loadResult = TEX_FAILED;
}
Texture::~Texture()
@ -262,6 +263,7 @@ void Texture::reload()
bool Texture::load(std::string file)
{
loadResult = TEX_FAILED;
if (file.size()<4)
{
errorLog("Texture Name is Empty or Too Short");
@ -430,6 +432,7 @@ bool Texture::loadPNG(const std::string &file)
width = info.Width;
height = info.Height;
good = true;
loadResult = TEX_SUCCESS;
}
else
{
@ -486,6 +489,7 @@ bool Texture::loadTGA(ImageTGA *imageTGA)
delete[] (imageTGA->data);
free (imageTGA);
loadResult = TEX_SUCCESS;
return true;
}

View file

@ -23,11 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Base.h"
enum TextureLoadResult
{
TEX_FAILED = 0x00,
TEX_SUCCESS = 0x01,
TEX_LOADED = 0x02,
TEX_FAILED,
TEX_SUCCESS
};
struct ImageTGA
@ -81,6 +81,8 @@ public:
std::string name;
TextureLoadResult getLoadResult() const { return loadResult; }
protected:
std::string loadName;
@ -91,6 +93,7 @@ protected:
bool loadTGA(ImageTGA *tga);
int ow, oh;
TextureLoadResult loadResult;
};