Skip to content

Commit

Permalink
Fix new [] / delete mismatch
Browse files Browse the repository at this point in the history
Using a custom deallocator to avoid breaking ABI

Alternatively C++17 supports the following syntax, which was not used:

`typedef std::shared_ptr<unsigned char[]> DataPtr;`

Signed-off-by: Matias N. Goldberg <[email protected]>
  • Loading branch information
darksylinc committed Jun 14, 2021
1 parent f9f1820 commit 8f8b074
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
using namespace ignition;
using namespace rendering;

//////////////////////////////////////////////////
template <class T>
struct ArrayDeleter
{
void operator () (T const * p)
{
delete [] p;
}
};

//////////////////////////////////////////////////
Image::Image(unsigned int _width, unsigned int _height,
PixelFormat _format) :
Expand All @@ -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<unsigned char>());
}

//////////////////////////////////////////////////
Expand Down

0 comments on commit 8f8b074

Please sign in to comment.