mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
Improved the error message given when jpeg, TGA, and BMP images fail to decode.
This commit is contained in:
@@ -78,7 +78,7 @@ bool FileData::getConstant(const char *in, Decoder &out)
|
|||||||
return decoders.find(in, out);
|
return decoders.find(in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileData::getConstant(Decoder in, const char *&out)
|
bool FileData::getConstant(Decoder in, const char *&out)
|
||||||
{
|
{
|
||||||
return decoders.find(in, out);
|
return decoders.find(in, out);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public:
|
|||||||
const std::string &getExtension() const;
|
const std::string &getExtension() const;
|
||||||
|
|
||||||
static bool getConstant(const char *in, Decoder &out);
|
static bool getConstant(const char *in, Decoder &out);
|
||||||
static bool getConstant(Decoder in, const char *&out);
|
static bool getConstant(Decoder in, const char *&out);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -124,10 +124,7 @@ void ImageData::decode(love::filesystem::FileData *data)
|
|||||||
// The decoder *must* output a 32 bits-per-pixel image.
|
// The decoder *must* output a 32 bits-per-pixel image.
|
||||||
if (decodedimage.size != decodedimage.width*decodedimage.height*sizeof(pixel))
|
if (decodedimage.size != decodedimage.width*decodedimage.height*sizeof(pixel))
|
||||||
{
|
{
|
||||||
if (decodeHandler)
|
decoder->free(decodedimage.data);
|
||||||
decodeHandler->free(decodedimage.data);
|
|
||||||
else
|
|
||||||
delete[] decodedimage.data;
|
|
||||||
throw love::Exception("Could not convert image!");
|
throw love::Exception("Could not convert image!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,12 @@ FormatHandler::DecodedImage STBHandler::decode(love::filesystem::FileData *data)
|
|||||||
&comp, 4);
|
&comp, 4);
|
||||||
|
|
||||||
if (img.data == nullptr || img.width <= 0 || img.height <= 0)
|
if (img.data == nullptr || img.width <= 0 || img.height <= 0)
|
||||||
throw love::Exception("Could not decode image with stb_image.");
|
{
|
||||||
|
const char *err = stbi_failure_reason();
|
||||||
|
if (err == nullptr)
|
||||||
|
err = "unknown error";
|
||||||
|
throw love::Exception("Could not decode image with stb_image (%s).", err);
|
||||||
|
}
|
||||||
|
|
||||||
img.size = img.width * img.height * 4;
|
img.size = img.width * img.height * 4;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user