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>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-15 05:31:22 +00:00
co-authored by 78
parent 01603c5112
commit a6357c4640
+5
View File
@@ -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();
}