From 80912d075d5a8f75a61bace913e8dca1c7f97708 Mon Sep 17 00:00:00 2001 From: Bodmer Date: Fri, 3 Feb 2023 19:39:24 +0000 Subject: [PATCH] Fix #2376 --- Extensions/Sprite.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Extensions/Sprite.cpp b/Extensions/Sprite.cpp index 80dadfe..21aaca8 100644 --- a/Extensions/Sprite.cpp +++ b/Extensions/Sprite.cpp @@ -223,11 +223,6 @@ void* TFT_eSprite::callocSprite(int16_t w, int16_t h, uint8_t frames) ***************************************************************************************/ void TFT_eSprite::createPalette(uint16_t colorMap[], uint8_t colors) { - if (_colorMap != nullptr) - { - free(_colorMap); - } - if (colorMap == nullptr) { // Create a color map using the default FLASH map @@ -236,7 +231,7 @@ void TFT_eSprite::createPalette(uint16_t colorMap[], uint8_t colors) } // Allocate and clear memory for 16 color map - _colorMap = (uint16_t *)calloc(16, sizeof(uint16_t)); + if (_colorMap == nullptr) _colorMap = (uint16_t *)calloc(16, sizeof(uint16_t)); if (colors > 16) colors = 16; @@ -261,7 +256,7 @@ void TFT_eSprite::createPalette(const uint16_t colorMap[], uint8_t colors) } // Allocate and clear memory for 16 color map - _colorMap = (uint16_t *)calloc(16, sizeof(uint16_t)); + if (_colorMap == nullptr) _colorMap = (uint16_t *)calloc(16, sizeof(uint16_t)); if (colors > 16) colors = 16; @@ -380,7 +375,7 @@ void TFT_eSprite::deleteSprite(void) if (_colorMap != nullptr) { free(_colorMap); - _colorMap = nullptr; + _colorMap = nullptr; } if (_created)