From 564e929aea50b125d5d4454b2232f3ca9e31158f Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Mar 2026 22:14:02 +0800 Subject: [PATCH] Fix race condition in GIF emotion switching causing crash (#1848) * Initial plan * Fix GIF emotion switching crash: hide emoji_image_ before destroying gif_controller_ The crash was caused by a race condition in SetEmotion() where two separate DisplayLockGuard scopes allowed the LVGL render task to access freed GIF image data between lock scopes. By hiding emoji_image_ before destroying gif_controller_ in the same lock scope, LVGL won't try to render the image with freed data during the gap. Co-authored-by: 78 <4488133+78@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: 78 <4488133+78@users.noreply.github.com> --- main/display/lcd_display.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main/display/lcd_display.cc b/main/display/lcd_display.cc index 239e10f..9d110e0 100644 --- a/main/display/lcd_display.cc +++ b/main/display/lcd_display.cc @@ -1079,6 +1079,11 @@ void LcdDisplay::SetEmotion(const char* emotion) { if (gif_controller_) { DisplayLockGuard lock(this); gif_controller_->Stop(); + // Hide image before destroying GIF controller to prevent LVGL from + // accessing freed image data during rendering between lock scopes + if (emoji_image_) { + lv_obj_add_flag(emoji_image_, LV_OBJ_FLAG_HIDDEN); + } gif_controller_.reset(); }