From 37ac1466b43d337cb4aa1f66df9f7a41f7b8dc86 Mon Sep 17 00:00:00 2001 From: GPayne Date: Sun, 18 Oct 2020 14:13:27 -0600 Subject: [PATCH] Fix for crash if screenspace image load fails --- ext/ghoul | 2 +- .../rendering/renderableplaneimageonline.cpp | 34 ++++++++++-------- .../base/rendering/screenspaceimageonline.cpp | 36 +++++++++++-------- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index a9842afb9e..e75af2a3be 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit a9842afb9ee64f636c746844dfa8ec2eecaca582 +Subproject commit e75af2a3be7cf1b71db04e4a083efa899a2faa01 diff --git a/modules/base/rendering/renderableplaneimageonline.cpp b/modules/base/rendering/renderableplaneimageonline.cpp index 148da49c50..3914cd2ae0 100644 --- a/modules/base/rendering/renderableplaneimageonline.cpp +++ b/modules/base/rendering/renderableplaneimageonline.cpp @@ -120,24 +120,30 @@ void RenderablePlaneImageOnline::update(const UpdateData&) { return; } - std::unique_ptr texture = - ghoul::io::TextureReader::ref().loadTexture( - reinterpret_cast(imageFile.buffer), - imageFile.size, - imageFile.format - ); + try { + std::unique_ptr texture = + ghoul::io::TextureReader::ref().loadTexture( + reinterpret_cast(imageFile.buffer), + imageFile.size, + imageFile.format + ); - if (texture) { - // Images don't need to start on 4-byte boundaries, for example if the - // image is only RGB - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + if (texture) { + // Images don't need to start on 4-byte boundaries, for example if the + // image is only RGB + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - texture->uploadTexture(); - texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); - texture->purgeFromRAM(); + texture->uploadTexture(); + texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); + texture->purgeFromRAM(); - _texture = std::move(texture); + _texture = std::move(texture); + _textureIsDirty = false; + } + } + catch (const ghoul::io::TextureReader::InvalidLoadException& e) { _textureIsDirty = false; + LERRORC(e.component, e.message); } } } diff --git a/modules/base/rendering/screenspaceimageonline.cpp b/modules/base/rendering/screenspaceimageonline.cpp index 10ad87dbde..5dd4b7c736 100644 --- a/modules/base/rendering/screenspaceimageonline.cpp +++ b/modules/base/rendering/screenspaceimageonline.cpp @@ -129,25 +129,31 @@ void ScreenSpaceImageOnline::update() { return; } - std::unique_ptr texture = - ghoul::io::TextureReader::ref().loadTexture( - reinterpret_cast(imageFile.buffer), - imageFile.size, - imageFile.format - ); + try { + std::unique_ptr texture = + ghoul::io::TextureReader::ref().loadTexture( + reinterpret_cast(imageFile.buffer), + imageFile.size, + imageFile.format + ); - if (texture) { - // Images don't need to start on 4-byte boundaries, for example if the - // image is only RGB - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + if (texture) { + // Images don't need to start on 4-byte boundaries, for example if the + // image is only RGB + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - texture->uploadTexture(); - texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); - texture->purgeFromRAM(); + texture->uploadTexture(); + texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); + texture->purgeFromRAM(); - _texture = std::move(texture); - _objectSize = _texture->dimensions(); + _texture = std::move(texture); + _objectSize = _texture->dimensions(); + _textureIsDirty = false; + } + } + catch (const ghoul::io::TextureReader::InvalidLoadException& e) { _textureIsDirty = false; + LERRORC(e.component, e.message); } } }