mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-12-01 10:35:38 +00:00
Fixed an issue with an endless loop when attempting to load a corrupt image file.
This commit is contained in:
parent
506a452d1b
commit
651b7a4d02
|
@ -426,7 +426,8 @@ void ImageComponent::render(const Transform4x4f& parentTrans)
|
||||||
mTargetSize.y(), 0xFF000033, 0xFF000033);
|
mTargetSize.y(), 0xFF000033, 0xFF000033);
|
||||||
Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), 0xFF000033, 0xFF000033);
|
Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), 0xFF000033, 0xFF000033);
|
||||||
}
|
}
|
||||||
if (mTexture->isInitialized()) {
|
// An image with zero size would normally indicate a corrupt image file.
|
||||||
|
if (mTexture->isInitialized() && mTexture->getSize() != 0) {
|
||||||
// Actually draw the image.
|
// Actually draw the image.
|
||||||
// The bind() function returns false if the texture is not currently loaded. A blank
|
// The bind() function returns false if the texture is not currently loaded. A blank
|
||||||
// texture is bound in this case but we want to handle a fade so it doesn't just
|
// texture is bound in this case but we want to handle a fade so it doesn't just
|
||||||
|
@ -441,7 +442,19 @@ void ImageComponent::render(const Transform4x4f& parentTrans)
|
||||||
Renderer::drawTriangleStrips(&mVertices[0], 4, trans);
|
Renderer::drawTriangleStrips(&mVertices[0], 4, trans);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG(LogError) << "Image texture is not initialized!";
|
if (!mTexture) {
|
||||||
|
LOG(LogError) << "Image texture is not initialized";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::string textureFilePath = mTexture->getTextureFilePath();
|
||||||
|
if (textureFilePath != "") {
|
||||||
|
LOG(LogError) << "Image texture for file \"" << textureFilePath <<
|
||||||
|
"\" has zero size";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LOG(LogError) << "Image texture has zero size";
|
||||||
|
}
|
||||||
|
}
|
||||||
mTexture.reset();
|
mTexture.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ bool TextureData::initImageFromMemory(const unsigned char* fileData, size_t leng
|
||||||
|
|
||||||
if (imageRGBA.size() == 0) {
|
if (imageRGBA.size() == 0) {
|
||||||
LOG(LogError) << "Couldn't initialize texture from memory, invalid data (" <<
|
LOG(LogError) << "Couldn't initialize texture from memory, invalid data (" <<
|
||||||
(mPath != "" ? "file path: " + mPath + ", " : "") << "data ptr: " <<
|
(mPath != "" ? "file path: \"" + mPath + "\", " : "") << "data ptr: " <<
|
||||||
reinterpret_cast<size_t>(fileData) << ", reported size: " << length << ")";
|
reinterpret_cast<size_t>(fileData) << ", reported size: " << length << ")";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ public:
|
||||||
void setScaleDuringLoad(float scale) { mScaleDuringLoad = scale; }
|
void setScaleDuringLoad(float scale) { mScaleDuringLoad = scale; }
|
||||||
|
|
||||||
std::vector<unsigned char> getRawRGBAData() { return mDataRGBA; }
|
std::vector<unsigned char> getRawRGBAData() { return mDataRGBA; }
|
||||||
|
std::string getTextureFilePath() { return mPath; }
|
||||||
bool tiled() { return mTile; }
|
bool tiled() { return mTile; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -115,6 +115,16 @@ std::vector<unsigned char> TextureResource::getRawRGBAData()
|
||||||
return std::vector<unsigned char>(0);
|
return std::vector<unsigned char>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string TextureResource::getTextureFilePath()
|
||||||
|
{
|
||||||
|
std::shared_ptr<TextureData> data = sTextureDataManager.get(this);
|
||||||
|
|
||||||
|
if (data)
|
||||||
|
return data->getTextureFilePath();
|
||||||
|
else
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
const Vector2i TextureResource::getSize() const
|
const Vector2i TextureResource::getSize() const
|
||||||
{
|
{
|
||||||
return mSize;
|
return mSize;
|
||||||
|
|
|
@ -39,6 +39,8 @@ public:
|
||||||
// Returns the raw pixel values.
|
// Returns the raw pixel values.
|
||||||
std::vector<unsigned char> getRawRGBAData();
|
std::vector<unsigned char> getRawRGBAData();
|
||||||
|
|
||||||
|
std::string getTextureFilePath();
|
||||||
|
|
||||||
// For SVG graphics this function effectively rescales the image to the defined size.
|
// For SVG graphics this function effectively rescales the image to the defined size.
|
||||||
// It does unload and re-rasterize the texture though which may cause flickering in some
|
// It does unload and re-rasterize the texture though which may cause flickering in some
|
||||||
// situations. An alternative is to set a scaling factor directly when loading the texture
|
// situations. An alternative is to set a scaling factor directly when loading the texture
|
||||||
|
|
Loading…
Reference in a new issue