mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 15:45: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);
|
||||
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.
|
||||
// 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
|
||||
|
@ -441,7 +442,19 @@ void ImageComponent::render(const Transform4x4f& parentTrans)
|
|||
Renderer::drawTriangleStrips(&mVertices[0], 4, trans);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ bool TextureData::initImageFromMemory(const unsigned char* fileData, size_t leng
|
|||
|
||||
if (imageRGBA.size() == 0) {
|
||||
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 << ")";
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ public:
|
|||
void setScaleDuringLoad(float scale) { mScaleDuringLoad = scale; }
|
||||
|
||||
std::vector<unsigned char> getRawRGBAData() { return mDataRGBA; }
|
||||
std::string getTextureFilePath() { return mPath; }
|
||||
bool tiled() { return mTile; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -115,6 +115,16 @@ std::vector<unsigned char> TextureResource::getRawRGBAData()
|
|||
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
|
||||
{
|
||||
return mSize;
|
||||
|
|
|
@ -39,6 +39,8 @@ public:
|
|||
// Returns the raw pixel values.
|
||||
std::vector<unsigned char> getRawRGBAData();
|
||||
|
||||
std::string getTextureFilePath();
|
||||
|
||||
// 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
|
||||
// situations. An alternative is to set a scaling factor directly when loading the texture
|
||||
|
|
Loading…
Reference in a new issue