fix: Memoryleaks & Coredump, if no Grabber compiled (#724)

* Fix Memoryleaks & Coredump, if no Grabber

* Fix Memoryleaks & Coredump, if no Grabber
This commit is contained in:
LordGrey 2020-03-22 22:07:19 +01:00 committed by GitHub
parent 1fb14b2002
commit 49b30c47f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 10 deletions

View File

@ -69,8 +69,11 @@ void ImageProcessor::setSize(const unsigned width, const unsigned height)
return;
}
// Clean up the old buffer and mapping
_imageToLeds = 0;
if ( _imageToLeds != nullptr)
{
// Clean up the old buffer and mapping
delete _imageToLeds;
}
// Construct a new buffer and mapping
_imageToLeds = (width>0 && height>0) ? (new ImageToLedsMap(width, height, 0, 0, _ledString.leds())) : nullptr;
@ -78,17 +81,20 @@ void ImageProcessor::setSize(const unsigned width, const unsigned height)
void ImageProcessor::setLedString(const LedString& ledString)
{
_ledString = ledString;
if ( _imageToLeds != nullptr)
{
_ledString = ledString;
// get current width/height
const unsigned width = _imageToLeds->width();
const unsigned height = _imageToLeds->height();
// get current width/height
unsigned width = _imageToLeds->width();
unsigned height = _imageToLeds->height();
// Clean up the old buffer and mapping
_imageToLeds = 0;
// Clean up the old buffer and mapping
delete _imageToLeds;
// Construct a new buffer and mapping
_imageToLeds = new ImageToLedsMap(width, height, 0, 0, _ledString.leds());
// Construct a new buffer and mapping
_imageToLeds = new ImageToLedsMap(width, height, 0, 0, _ledString.leds());
}
}
void ImageProcessor::setBlackbarDetectDisable(bool enable)