From 00438fffd2321e7d768ded9277c3143448112cdc Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 7 May 2015 23:07:20 +0200 Subject: [PATCH] + before trying to write out snapshot image check if it's null --- src/Gui/SoFCOffscreenRenderer.cpp | 12 ++++++++++-- src/Gui/View3DInventorViewer.cpp | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Gui/SoFCOffscreenRenderer.cpp b/src/Gui/SoFCOffscreenRenderer.cpp index 537500bdf..90a9ddd1e 100644 --- a/src/Gui/SoFCOffscreenRenderer.cpp +++ b/src/Gui/SoFCOffscreenRenderer.cpp @@ -94,6 +94,12 @@ void SoFCOffscreenRenderer::writeToImage (QImage& img) const void SoFCOffscreenRenderer::writeToImageFile(const char* filename, const char* comment, const SbMatrix& mat, const QImage& image) { + if (image.isNull()) { + std::stringstream str; + str << "Cannot save null image."; + throw Base::ValueError(str.str()); + } + Base::FileInfo file(filename); if (file.hasExtension("JPG") || file.hasExtension("JPEG")) { // writing comment in case of jpeg (Qt ignores setText() in case of jpeg) @@ -163,13 +169,15 @@ void SoFCOffscreenRenderer::writeToImageFile(const char* filename, const char* c f.close(); std::stringstream str; str << "Cannot save image to file '" << filename << "'."; - throw Base::Exception(str.str()); + throw Base::ValueError(str.str()); } } else { std::stringstream str; str << "Cannot open file '" << filename << "' for writing."; - throw Base::Exception(str.str()); + Base::FileException e; + e.setMessage(str.str()); + throw e; } } // diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index a61eae760..6660e1e14 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -899,7 +899,7 @@ void View3DInventorViewer::savePicture(int w, int h, const QColor& bg, QImage& i #if (COIN_MAJOR_VERSION >= 4) // The behaviour in Coin4 has changed so that when using the same instance of 'SoFCOffscreenRenderer' // multiple times internally the biggest viewport size is stored and set to the SoGLRenderAction. - // The trick is to add a callback node and override the viewport size with wath we want. + // The trick is to add a callback node and override the viewport size with what we want. //SoCallback* cbvp = new SoCallback; //cbvp->setCallback(setViewportCB); //root->addChild(cbvp);