Skip to content

Commit

Permalink
Add more warnings for out-of-memory
Browse files Browse the repository at this point in the history
  • Loading branch information
gzotti committed Oct 12, 2023
1 parent 72e81dc commit 7474aa1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/core/StelTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ 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 @@ -134,7 +137,10 @@ StelTexture::GLData StelTexture::loadFromPath(const QString &path, const int dec
{
try
{
return imageToGLData(QImage(path), decimateBy);
QImage img(path);
if (img.isNull())
throw std::bad_alloc();
return imageToGLData(img, decimateBy);
}
catch(std::bad_alloc& ex) //this catches out-of-memory errors from file conversion
{
Expand Down
6 changes: 6 additions & 0 deletions src/core/modules/Landscape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ void LandscapeOldStyle::load(const QSettings& landscapeIni, const QString& lands
// if that query is not going to be prevented by the polygon that already has been loaded at that point...
if ( (!horizonPolygon) && calibrated ) { // for uncalibrated landscapes the texture is currently never queried, so no need to store.
QImage *image = new QImage(texturePath);
if (image->isNull())
qWarning() << "Null image (out of memory!) in Landscape!";

This comment has been minimized.

Copy link
@10110111

10110111 Oct 12, 2023

Contributor

Out of memory is not the only possible reason for a null image. Another is failure to read the file (e.g. no file or permission denied) or to decode it (e.g. corrupt data or unsupported format).

sidesImages.append(image); // indices identical to those in sideTexs
memorySize+=(image->sizeInBytes());
}
Expand Down Expand Up @@ -1567,6 +1569,8 @@ void LandscapeFisheye::create(const QString _name, float _texturefov, const QStr
{
mapImage = new QImage(_maptex);
memorySize+=(mapImage->sizeInBytes());
if (mapImage->isNull())
qWarning() << "Null image in Landscape" << _name << "- cannot load" << _maptex;
}
mapTex = texMan.createTexture(_maptex, StelTexture::StelTextureParams(true));
memorySize+=mapTex->getGlSize();
Expand Down Expand Up @@ -1852,6 +1856,8 @@ void LandscapeSpherical::create(const QString _name, const QString& _maptex, con
{
mapImage = new QImage(_maptex);
memorySize+=(mapImage->sizeInBytes());
if (mapImage->isNull())
qWarning() << "Null image in Landscape" << _name << "- cannot load" << _maptex;
}

auto& gl = *QOpenGLContext::currentContext()->functions();
Expand Down

0 comments on commit 7474aa1

Please sign in to comment.