Skip to content

Commit 0944f73

Browse files
committed
pixelcade: fix memory leak. change IsV23 to FirmwareVersion
1 parent 3ea2e18 commit 0944f73

File tree

3 files changed

+21
-53
lines changed

3 files changed

+21
-53
lines changed

src/DMD.cpp

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ void DMD::PixelcadeDMDThread()
12461246
else
12471247
continue;
12481248

1249-
if (m_pPixelcadeDMD->GetIsV23())
1249+
if (m_pPixelcadeDMD->GetIsV2())
12501250
{
12511251
m_pPixelcadeDMD->UpdateRGB24(scaledBuffer);
12521252
}
@@ -1263,6 +1263,8 @@ void DMD::PixelcadeDMDThread()
12631263
}
12641264
update = true;
12651265
}
1266+
1267+
delete[] scaledBuffer;
12661268
}
12671269
else if (m_pUpdateBufferQueue[bufferPositionMod]->mode == Mode::RGB16)
12681270
{
@@ -1277,23 +1279,7 @@ void DMD::PixelcadeDMDThread()
12771279
else
12781280
continue;
12791281

1280-
if (m_pPixelcadeDMD->GetIsV23())
1281-
{
1282-
uint8_t* rgb24Data = new uint8_t[targetLength * 3];
1283-
for (int i = 0; i < targetLength; i++)
1284-
{
1285-
uint16_t pixel = rgb565Data[i];
1286-
rgb24Data[i * 3] = (pixel >> 8) & 0xF8; // Red
1287-
rgb24Data[i * 3 + 1] = (pixel >> 3) & 0xFC; // Green
1288-
rgb24Data[i * 3 + 2] = (pixel << 3) & 0xF8; // Blue
1289-
}
1290-
m_pPixelcadeDMD->UpdateRGB24(rgb24Data);
1291-
delete[] rgb24Data;
1292-
}
1293-
else
1294-
{
1295-
update = true;
1296-
}
1282+
update = true;
12971283
}
12981284
else if (IsSerumV2Mode(m_pUpdateBufferQueue[bufferPositionMod]->mode))
12991285
{
@@ -1375,26 +1361,7 @@ void DMD::PixelcadeDMDThread()
13751361
}
13761362
}
13771363

1378-
if (update)
1379-
{
1380-
if (m_pPixelcadeDMD->GetIsV23())
1381-
{
1382-
uint8_t* rgb24Data = new uint8_t[targetLength * 3];
1383-
for (int i = 0; i < targetLength; i++)
1384-
{
1385-
uint16_t pixel = rgb565Data[i];
1386-
rgb24Data[i * 3] = (pixel >> 8) & 0xF8; // Red
1387-
rgb24Data[i * 3 + 1] = (pixel >> 3) & 0xFC; // Green
1388-
rgb24Data[i * 3 + 2] = (pixel << 3) & 0xF8; // Blue
1389-
}
1390-
m_pPixelcadeDMD->UpdateRGB24(rgb24Data);
1391-
delete[] rgb24Data;
1392-
}
1393-
else
1394-
{
1395-
m_pPixelcadeDMD->Update(rgb565Data);
1396-
}
1397-
}
1364+
if (update) m_pPixelcadeDMD->Update(rgb565Data);
13981365
}
13991366
}
14001367
}

src/PixelcadeDMD.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
namespace DMDUtil
1717
{
1818

19-
PixelcadeDMD::PixelcadeDMD(struct sp_port* pSerialPort, int width, int height, bool colorSwap, bool isV2, bool isV23)
19+
PixelcadeDMD::PixelcadeDMD(struct sp_port* pSerialPort, int width, int height, bool colorSwap, bool isV2,
20+
int firmwareVersion)
2021
{
2122
m_pSerialPort = pSerialPort;
2223
m_width = width;
2324
m_height = height;
2425
m_colorSwap = colorSwap;
2526
m_isV2 = isV2;
26-
m_isV23 = isV23;
27+
m_firmwareVersion = firmwareVersion;
2728
m_length = width * height;
2829
m_pThread = nullptr;
2930
m_running = false;
@@ -140,7 +141,7 @@ PixelcadeDMD* PixelcadeDMD::Open(const char* pDevice)
140141
int width = 128;
141142
int height = 32;
142143
bool isV2 = false;
143-
bool isV23 = false;
144+
int firmwareVersion = 0;
144145
bool colorSwap = false;
145146

146147
if (firmware[0] == 'P' && firmware[1] != 0 && firmware[2] != 0 && firmware[3] != 0)
@@ -160,19 +161,18 @@ PixelcadeDMD* PixelcadeDMD::Open(const char* pDevice)
160161

161162
if (firmware[6] != 0 && firmware[7] != 0)
162163
{
163-
int version = (firmware[6] - '0') * 10 + (firmware[7] - '0');
164-
isV23 = (version >= 23);
164+
firmwareVersion = (firmware[6] - '0') * 10 + (firmware[7] - '0');
165165
}
166166

167167
colorSwap = (firmware[4] == 'C') && !isV2;
168168
}
169169

170170
Log(DMDUtil_LogLevel_INFO,
171-
"Pixelcade found: device=%s, Hardware ID=%s, Bootloader ID=%s, Firmware=%s, Size=%dx%d, V2=%d, V23=%d, "
171+
"Pixelcade found: device=%s, Hardware ID=%s, Bootloader ID=%s, Firmware=%s, Size=%dx%d, V2=%d, FW=%d, "
172172
"ColorSwap=%d",
173-
pDevice, hardwareId, bootloaderId, firmware, width, height, isV2, isV23, colorSwap);
173+
pDevice, hardwareId, bootloaderId, firmware, width, height, isV2, firmwareVersion, colorSwap);
174174

175-
return new PixelcadeDMD(pSerialPort, width, height, colorSwap, isV2, isV23);
175+
return new PixelcadeDMD(pSerialPort, width, height, colorSwap, isV2, firmwareVersion);
176176
}
177177

178178
void PixelcadeDMD::Update(uint16_t* pData)
@@ -247,11 +247,12 @@ void PixelcadeDMD::EnableRgbLedMatrix(int shifterLen32, int rows)
247247

248248
if (m_isV2)
249249
{
250-
uint8_t command = m_isV23 ? PIXELCADE_COMMAND_RGB_LED_MATRIX_ENABLE_V23 : PIXELCADE_COMMAND_RGB_LED_MATRIX_ENABLE;
250+
uint8_t command =
251+
(m_firmwareVersion >= 23) ? PIXELCADE_COMMAND_RGB_LED_MATRIX_ENABLE_V23 : PIXELCADE_COMMAND_RGB_LED_MATRIX_ENABLE;
251252
uint8_t frame[8];
252253
int frameSize;
253254

254-
if (m_isV23)
255+
if (m_firmwareVersion >= 23)
255256
{
256257
frameSize = BuildFrame(frame, sizeof(frame), command, &configData, 1);
257258
}
@@ -280,7 +281,7 @@ void PixelcadeDMD::Run()
280281
{
281282
Log(DMDUtil_LogLevel_INFO, "PixelcadeDMD run thread starting");
282283

283-
if (m_isV23)
284+
if (m_firmwareVersion >= 23)
284285
{
285286
uint8_t initCmd = PIXELCADE_COMMAND_V23_INIT;
286287
sp_blocking_write(m_pSerialPort, &initCmd, 1, 0);
@@ -337,7 +338,7 @@ void PixelcadeDMD::Run()
337338
}
338339

339340
int frameSize;
340-
if (m_isV23)
341+
if (m_firmwareVersion >= 23)
341342
{
342343
memcpy(pFrameData + 5, frame.pData, payloadSize);
343344
frameSize = BuildFrame(pFrameData, maxFrameDataSize + 10, command, pFrameData + 5, payloadSize);

src/PixelcadeDMD.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct PixelcadeFrame
4646
class PixelcadeDMD
4747
{
4848
public:
49-
PixelcadeDMD(struct sp_port* pSerialPort, int width, int height, bool colorSwap, bool isV2, bool isV23);
49+
PixelcadeDMD(struct sp_port* pSerialPort, int width, int height, bool colorSwap, bool isV2, int firmwareVersion);
5050
~PixelcadeDMD();
5151

5252
static PixelcadeDMD* Connect(const char* pDevice = nullptr);
@@ -56,7 +56,7 @@ class PixelcadeDMD
5656
int GetWidth() const { return m_width; }
5757
int GetHeight() const { return m_height; }
5858
bool GetIsV2() const { return m_isV2; }
59-
bool GetIsV23() const { return m_isV23; }
59+
int GetFirmwareVersion() const { return m_firmwareVersion; }
6060

6161
private:
6262
static PixelcadeDMD* Open(const char* pDevice);
@@ -71,7 +71,7 @@ class PixelcadeDMD
7171
int m_height;
7272
bool m_colorSwap;
7373
bool m_isV2;
74-
bool m_isV23;
74+
int m_firmwareVersion;
7575
int m_length;
7676

7777
std::thread* m_pThread;

0 commit comments

Comments
 (0)