Skip to content

Commit aeb8405

Browse files
H7 Video + LVGL 9: fix buffer flush size and add free()
1 parent 70c0aed commit aeb8405

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

libraries/Arduino_H7_Video/src/Arduino_H7_Video.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ void lvgl_displayFlushing(lv_display_t * disp, const lv_area_t * area, unsigned
251251
lv_display_rotation_t rotation = lv_display_get_rotation(disp);
252252
lv_area_t rotated_area;
253253
if (rotation != LV_DISPLAY_ROTATION_0) {
254-
rotated_buf = (uint8_t*)realloc(rotated_buf, w * h * 4);
254+
uint8_t* new_buf = (uint8_t*)realloc(rotated_buf, w * h * 2);
255+
if (new_buf == NULL) {
256+
return; // Insufficient memory error
257+
}
258+
rotated_buf = new_buf;
255259
lv_color_format_t cf = lv_display_get_color_format(disp);
256260
#if (LVGL_VERSION_MINOR < 2)
257261
rotation = LV_DISPLAY_ROTATION_90; // bugfix: force 90 degree rotation for lvgl 9.1 end earlier
@@ -277,6 +281,13 @@ void lvgl_displayFlushing(lv_display_t * disp, const lv_area_t * area, unsigned
277281
uint32_t offsetPos = (area_in_use->x1 + (dsi_getDisplayXSize() * area_in_use->y1)) * sizeof(uint16_t);
278282

279283
dsi_lcdDrawImage((void *) px_map, (void *)(dsi_getActiveFrameBuffer() + offsetPos), w, h, DMA2D_INPUT_RGB565);
284+
285+
// free the rotated buffer if it was allocated
286+
if (rotation != LV_DISPLAY_ROTATION_0) {
287+
free(rotated_buf);
288+
rotated_buf = nullptr;
289+
}
290+
280291
lv_display_flush_ready(disp); /* Indicate you are ready with the flushing*/
281292
}
282293
#else

0 commit comments

Comments
 (0)