mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-02-18 02:34:57 +00:00
Fix rare texture loading problems introduced in 8bd40be8aa
and f0d580d873
.
This commit is contained in:
parent
198f0353d5
commit
62c949f640
5 changed files with 29 additions and 32 deletions
|
@ -4429,7 +4429,7 @@ std::string Core::getTextureLoadName(const std::string &texture)
|
||||||
return loadName;
|
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))
|
if (texture.empty() || !ISPATHROOT(texture))
|
||||||
{
|
{
|
||||||
|
@ -4448,35 +4448,28 @@ std::pair<CountedPtr<Texture>, TextureLoadResult> Core::doTextureAdd(const std::
|
||||||
stringToLowerUserData(internalTextureName);
|
stringToLowerUserData(internalTextureName);
|
||||||
CountedPtr<Texture> t = core->findTexture(internalTextureName);
|
CountedPtr<Texture> t = core->findTexture(internalTextureName);
|
||||||
if (t)
|
if (t)
|
||||||
return std::make_pair(t, TEX_SUCCESS);
|
return t;
|
||||||
|
|
||||||
t = new Texture;
|
t = new Texture;
|
||||||
t->name = internalTextureName;
|
t->name = internalTextureName;
|
||||||
unsigned res = TEX_FAILED;
|
|
||||||
|
|
||||||
if(t->load(loadName))
|
if(!t->load(loadName))
|
||||||
res |= (TEX_LOADED | TEX_SUCCESS);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
t->width = 64;
|
t->width = 64;
|
||||||
t->height = 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);
|
BBGE_PROF(Core_addTexture);
|
||||||
|
|
||||||
if (textureName.empty())
|
if (textureName.empty())
|
||||||
{
|
|
||||||
if(pLoadResult)
|
|
||||||
*pLoadResult = TEX_FAILED;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
std::pair<CountedPtr<Texture>, TextureLoadResult> texResult;
|
CountedPtr<Texture> ptex;
|
||||||
std::string texture = textureName;
|
std::string texture = textureName;
|
||||||
stringToLowerUserData(texture);
|
stringToLowerUserData(texture);
|
||||||
std::string internalTextureName = texture;
|
std::string internalTextureName = texture;
|
||||||
|
@ -4493,33 +4486,31 @@ CountedPtr<Texture> Core::addTexture(const std::string &textureName, TextureLoad
|
||||||
std::string ln = loadName;
|
std::string ln = loadName;
|
||||||
texture = secondaryTexturePath + texture;
|
texture = secondaryTexturePath + texture;
|
||||||
loadName = texture;
|
loadName = texture;
|
||||||
texResult = doTextureAdd(texture, loadName, internalTextureName);
|
ptex = doTextureAdd(texture, loadName, internalTextureName);
|
||||||
if (!texResult.second)
|
if (!ptex || ptex->getLoadResult() == TEX_FAILED)
|
||||||
texResult = doTextureAdd(t, ln, internalTextureName);
|
ptex = doTextureAdd(t, ln, internalTextureName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
texResult = doTextureAdd(texture, loadName, internalTextureName);
|
ptex = doTextureAdd(texture, loadName, internalTextureName);
|
||||||
|
|
||||||
addTexture(texResult.first.content());
|
addTexture(ptex.content());
|
||||||
|
|
||||||
if(debugLogTextures)
|
if(debugLogTextures)
|
||||||
{
|
{
|
||||||
if (texResult.second & TEX_LOADED)
|
if (ptex)
|
||||||
{
|
{
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "LOADED TEXTURE FROM DISK: [" << internalTextureName << "] idx: " << resources.size()-1;
|
os << "LOADED TEXTURE FROM DISK: [" << internalTextureName << "] idx: " << resources.size()-1;
|
||||||
debugLog(os.str());
|
debugLog(os.str());
|
||||||
}
|
}
|
||||||
else if(!(texResult.second & TEX_SUCCESS))
|
else if(ptex->getLoadResult() != TEX_SUCCESS)
|
||||||
{
|
{
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "FAILED TO LOAD TEXTURE: [" << internalTextureName << "] idx: " << resources.size()-1;
|
os << "FAILED TO LOAD TEXTURE: [" << internalTextureName << "] idx: " << resources.size()-1;
|
||||||
debugLog(os.str());
|
debugLog(os.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(pLoadResult)
|
return ptex;
|
||||||
*pLoadResult = texResult.second;
|
|
||||||
return texResult.first;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::addRenderObject(RenderObject *o, int layer)
|
void Core::addRenderObject(RenderObject *o, int layer)
|
||||||
|
|
|
@ -1023,7 +1023,7 @@ public:
|
||||||
void removeTexture(Texture *res);
|
void removeTexture(Texture *res);
|
||||||
void clearResources();
|
void clearResources();
|
||||||
|
|
||||||
CountedPtr<Texture> addTexture(const std::string &texture, TextureLoadResult *pLoadResult = 0);
|
CountedPtr<Texture> addTexture(const std::string &texture);
|
||||||
|
|
||||||
PostProcessingFX postProcessingFx;
|
PostProcessingFX postProcessingFx;
|
||||||
|
|
||||||
|
@ -1328,7 +1328,7 @@ protected:
|
||||||
|
|
||||||
virtual void onReloadResources();
|
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);
|
void deleteRenderObjectMemory(RenderObject *r);
|
||||||
bool _hasFocus;
|
bool _hasFocus;
|
||||||
|
|
|
@ -1365,13 +1365,12 @@ bool RenderObject::setTexture(const std::string &n)
|
||||||
if (name.empty())
|
if (name.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(texture && name == texture->name)
|
if(texture && texture->getLoadResult() == TEX_SUCCESS && name == texture->name)
|
||||||
return true; // no texture change
|
return true; // no texture change
|
||||||
|
|
||||||
TextureLoadResult res = TEX_FAILED;
|
CountedPtr<Texture> tex = core->addTexture(name);
|
||||||
CountedPtr<Texture> tex = core->addTexture(name, &res);
|
|
||||||
setTexturePointer(tex);
|
setTexturePointer(tex);
|
||||||
return !!tex && res != TEX_FAILED;
|
return tex && tex->getLoadResult() == TEX_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
float RenderObject::getSortDepth()
|
float RenderObject::getSortDepth()
|
||||||
|
|
|
@ -69,6 +69,7 @@ Texture::Texture()
|
||||||
repeating = false;
|
repeating = false;
|
||||||
pngSetStandardOrientation(0);
|
pngSetStandardOrientation(0);
|
||||||
ow = oh = -1;
|
ow = oh = -1;
|
||||||
|
loadResult = TEX_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::~Texture()
|
Texture::~Texture()
|
||||||
|
@ -262,6 +263,7 @@ void Texture::reload()
|
||||||
|
|
||||||
bool Texture::load(std::string file)
|
bool Texture::load(std::string file)
|
||||||
{
|
{
|
||||||
|
loadResult = TEX_FAILED;
|
||||||
if (file.size()<4)
|
if (file.size()<4)
|
||||||
{
|
{
|
||||||
errorLog("Texture Name is Empty or Too Short");
|
errorLog("Texture Name is Empty or Too Short");
|
||||||
|
@ -430,6 +432,7 @@ bool Texture::loadPNG(const std::string &file)
|
||||||
width = info.Width;
|
width = info.Width;
|
||||||
height = info.Height;
|
height = info.Height;
|
||||||
good = true;
|
good = true;
|
||||||
|
loadResult = TEX_SUCCESS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -486,6 +489,7 @@ bool Texture::loadTGA(ImageTGA *imageTGA)
|
||||||
delete[] (imageTGA->data);
|
delete[] (imageTGA->data);
|
||||||
free (imageTGA);
|
free (imageTGA);
|
||||||
|
|
||||||
|
loadResult = TEX_SUCCESS;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,11 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
|
|
||||||
|
|
||||||
enum TextureLoadResult
|
enum TextureLoadResult
|
||||||
{
|
{
|
||||||
TEX_FAILED = 0x00,
|
TEX_FAILED,
|
||||||
TEX_SUCCESS = 0x01,
|
TEX_SUCCESS
|
||||||
TEX_LOADED = 0x02,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ImageTGA
|
struct ImageTGA
|
||||||
|
@ -81,6 +81,8 @@ public:
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
|
TextureLoadResult getLoadResult() const { return loadResult; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string loadName;
|
std::string loadName;
|
||||||
|
|
||||||
|
@ -91,6 +93,7 @@ protected:
|
||||||
bool loadTGA(ImageTGA *tga);
|
bool loadTGA(ImageTGA *tga);
|
||||||
|
|
||||||
int ow, oh;
|
int ow, oh;
|
||||||
|
TextureLoadResult loadResult;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue