diff --git a/ogre2/src/Ogre2SelectionBuffer.cc b/ogre2/src/Ogre2SelectionBuffer.cc index a3aec839a..9ec622011 100644 --- a/ogre2/src/Ogre2SelectionBuffer.cc +++ b/ogre2/src/Ogre2SelectionBuffer.cc @@ -175,9 +175,12 @@ void Ogre2SelectionBuffer::CreateRTTBuffer() const_cast(scenePass)->mVisibilityMask = IGN_VISIBILITY_SELECTABLE; - // buffer to store render texture data - size_t bufferSize = Ogre::PixelUtil::getMemorySize(width, height, 1, format); + // buffer to store render texture data. Ensure it's at least 4 bytes + size_t bufferSize = std::max( + Ogre::PixelUtil::getMemorySize(width, height, 1, format), + 4u); this->dataPtr->buffer = new uint8_t[bufferSize]; + memset(this->dataPtr->buffer, 0, 4u); this->dataPtr->pixelBox = new Ogre::PixelBox(width, height, 1, format, this->dataPtr->buffer); } diff --git a/src/Image.cc b/src/Image.cc index 74ed14fb6..a2ad9cc43 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -19,6 +19,16 @@ using namespace ignition; using namespace rendering; +////////////////////////////////////////////////// +template +struct ArrayDeleter +{ + void operator () (T const * p) + { + delete [] p; + } +}; + ////////////////////////////////////////////////// Image::Image(unsigned int _width, unsigned int _height, PixelFormat _format) : @@ -27,7 +37,7 @@ Image::Image(unsigned int _width, unsigned int _height, { this->format = PixelUtil::Sanitize(_format); unsigned int size = this->MemorySize(); - this->data = DataPtr(new unsigned char[size]); + this->data = DataPtr(new unsigned char[size], ArrayDeleter()); } //////////////////////////////////////////////////