From 7f335fd528a476fe5157ed945160f7d4ffa557e5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 30 Jun 2016 08:20:31 +0100 Subject: [PATCH] Added handling of possible zero divisor --- src/osgPlugins/png/ReaderWriterPNG.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/osgPlugins/png/ReaderWriterPNG.cpp b/src/osgPlugins/png/ReaderWriterPNG.cpp index 29ef345cb..9e06425af 100644 --- a/src/osgPlugins/png/ReaderWriterPNG.cpp +++ b/src/osgPlugins/png/ReaderWriterPNG.cpp @@ -126,7 +126,8 @@ class ReaderWriterPNG : public osgDB::ReaderWriter } //wish there was a Image::computeComponentSizeInBits() - bitDepth = Image::computePixelSizeInBits(img.getPixelFormat(),img.getDataType())/Image::computeNumComponents(img.getPixelFormat()); + unsigned int numComponents = Image::computeNumComponents(img.getPixelFormat()); + bitDepth = (numComponents>0) ? (Image::computePixelSizeInBits(img.getPixelFormat(),img.getDataType())/numComponents) : 0; if(bitDepth!=8 && bitDepth!=16) return WriteResult::ERROR_IN_WRITING_FILE; //Create row data