Skip to content

Commit

Permalink
Somewhat cleaner error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
gzotti committed Oct 12, 2023
1 parent 7474aa1 commit 75b16d7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/core/StelTexture.cpp
Expand Up @@ -122,10 +122,7 @@ StelTexture::GLData StelTexture::imageToGLData(const QImage &image, const int de
{
GLData ret = GLData();
if (image.isNull())
{
qCritical() << "Image is null";
return ret;
}
ret.data = convertToGLFormat(image, ret.format, ret.type, decimateBy, ret.width, ret.height);
return ret;
}
Expand All @@ -137,9 +134,16 @@ StelTexture::GLData StelTexture::loadFromPath(const QString &path, const int dec
{
try
{
QImage img(path);
QImageReader imgReader(path);
QImage img = imgReader.read();
if (img.isNull())
throw std::bad_alloc();
{
QImageReader::ImageReaderError error=imgReader.error();
qCritical() << "Error reading image file " << path << ":" << imgReader.errorString();

if (error==QImageReader::InvalidDataError)
qCritical() << "This may also indicate an out-of-memory error.";
}
return imageToGLData(img, decimateBy);
}
catch(std::bad_alloc& ex) //this catches out-of-memory errors from file conversion
Expand Down

0 comments on commit 75b16d7

Please sign in to comment.