Skip to content

Arduino H7 Video - LVGL9.X Double buffer is allocated but never used #1043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thodorii opened this issue Mar 27, 2025 · 5 comments · Fixed by #1050
Closed

Arduino H7 Video - LVGL9.X Double buffer is allocated but never used #1043

thodorii opened this issue Mar 27, 2025 · 5 comments · Fixed by #1050
Assignees
Labels

Comments

@thodorii
Copy link

thodorii commented Mar 27, 2025

Hi, I've been running into what seems to be memory issues causing an MBED OS crash with LVGL. I was looking around to see draw buffer allocations and ran into this code. I am confused on the purpose of the 2nd draw buffer malloc when it is never used, is this an oversight?

Additionally, should this malloc size be multiplied by sizeof(lv_color_t) for the ideal lvgl recommendation of 1/10th buffer size

@facchinm
 

#if (LVGL_VERSION_MAJOR == 9)
/* Create a draw buffer */
static lv_color_t * buf1 = (lv_color_t*)malloc((width() * height() / 10)); /* Declare a buffer for 1/10 screen size */
if (buf1 == NULL) {
return 2; /* Insuff memory err */
}
static lv_color_t * buf2 = (lv_color_t*)malloc((width() * height() / 10)); /* Declare a buffer for 1/10 screen size */
if (buf2 == NULL) {
return 2; /* Insuff memory err */
}
lv_display_t *display;
if(_rotated) {
display = lv_display_create(height(), width());
lv_display_set_rotation(display, LV_DISPLAY_ROTATION_270);
//display->sw_rotate = 1;
} else {
display = lv_display_create(width(), height());
}
lv_display_set_buffers(display, buf1, NULL, width() * height() / 10, LV_DISPLAY_RENDER_MODE_PARTIAL); /*Initialize the display buffer.*/
lv_display_set_flush_cb(display, lvgl_displayFlushing);
lvgl_inc_thd.start(inc_thd);

@thodorii
Copy link
Author

thodorii commented Apr 7, 2025

I can confirm that after disabling the second buffer, I no longer see the MBED OS crashes I used to consistently get on lv_timer_handler().

@leonardocavagnis
Copy link
Member

Hi @thodorii
Yes, leaving there buf2 is probably an oversight.
Thanks for pointing it out!

But, I can't replicate the MBED OS crash. Please, could you post the sketch causing this?

@thodorii
Copy link
Author

Unfortunately I don't think I can share the sketch due to it being part of work.

But the crash is likely due to memory constraints and the double buffer was the thing putting it in crashing territory.

The MBED OS crashes were happening with lv_timer_handler() and I was never able to get an exact trace of where it crashed.

@leonardocavagnis
Copy link
Member

Ok, no problem! :)
I opened a PR with the suggested fix!

By the way, I decided not to increase the buffer size because, as suggested in the LVGL documentation, LV_DISPLAY_RENDER_MODE_PARTIAL can work with a buffer smaller than the display size.
I’m aware this could cause some stability issues, but increasing the buffer size would consume too much memory and lead to crashes.

@thodorii
Copy link
Author

Ok great!

Anecdotally I also started seeing far fewer white screens after removing the buffer #1004 , although they were not completely gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants