Skip to content

Commit aed2c7c

Browse files
authored
replace delete in EInkDynamicDisplay.{cpp,h} with std::unique_ptr (#9643)
Is part of the unique_ptr modernization effort.
1 parent e1f9ccd commit aed2c7c

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/graphics/EInkDynamicDisplay.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ EInkDynamicDisplay::EInkDynamicDisplay(uint8_t address, int sda, int scl, OLEDDI
1010
{
1111
// If tracking ghost pixels, grab memory
1212
#ifdef EINK_LIMIT_GHOSTING_PX
13-
dirtyPixels = new uint8_t[EInkDisplay::displayBufferSize](); // Init with zeros
13+
dirtyPixels = std::unique_ptr<uint8_t[]>(new uint8_t[EInkDisplay::displayBufferSize]()); // Init with zeros
1414
#endif
1515
}
1616

@@ -19,7 +19,7 @@ EInkDynamicDisplay::~EInkDynamicDisplay()
1919
{
2020
// If we were tracking ghost pixels, free the memory
2121
#ifdef EINK_LIMIT_GHOSTING_PX
22-
delete[] dirtyPixels;
22+
dirtyPixels = nullptr;
2323
#endif
2424
}
2525

@@ -454,7 +454,7 @@ void EInkDynamicDisplay::checkExcessiveGhosting()
454454
void EInkDynamicDisplay::resetGhostPixelTracking()
455455
{
456456
// Copy the current frame into dirtyPixels[] from the display buffer
457-
memcpy(dirtyPixels, EInkDisplay::buffer, EInkDisplay::displayBufferSize);
457+
memcpy(dirtyPixels.get(), EInkDisplay::buffer, EInkDisplay::displayBufferSize);
458458
}
459459
#endif // EINK_LIMIT_GHOSTING_PX
460460

src/graphics/EInkDynamicDisplay.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "configuration.h"
4+
#include <memory>
45

56
#if defined(USE_EINK) && defined(USE_EINK_DYNAMICDISPLAY)
67

@@ -116,11 +117,11 @@ class EInkDynamicDisplay : public EInkDisplay, protected concurrency::NotifiedWo
116117
// Optional - track ghosting, pixel by pixel
117118
// May 2024: no longer used by any display. Kept for possible future use.
118119
#ifdef EINK_LIMIT_GHOSTING_PX
119-
void countGhostPixels(); // Count any pixels which have moved from black to white since last full-refresh
120-
void checkExcessiveGhosting(); // Check if ghosting exceeds defined limit
121-
void resetGhostPixelTracking(); // Clear the dirty pixels array. Call when full-refresh cleans the display.
122-
uint8_t *dirtyPixels; // Any pixels that have been black since last full-refresh (dynamically allocated mem)
123-
uint32_t ghostPixelCount = 0; // Number of pixels with problematic ghosting. Retained here for LOG_DEBUG use
120+
void countGhostPixels(); // Count any pixels which have moved from black to white since last full-refresh
121+
void checkExcessiveGhosting(); // Check if ghosting exceeds defined limit
122+
void resetGhostPixelTracking(); // Clear the dirty pixels array. Call when full-refresh cleans the display.
123+
std::unique_ptr<uint8_t[]> dirtyPixels; // Any pixels that have been black since last full-refresh (dynamically allocated mem)
124+
uint32_t ghostPixelCount = 0; // Number of pixels with problematic ghosting. Retained here for LOG_DEBUG use
124125
#endif
125126

126127
// Conditional - async full refresh - only with modified meshtastic/GxEPD2

0 commit comments

Comments
 (0)