mirror of
https://github.com/lvgl/lvgl.git
synced 2024-11-23 09:43:41 +08:00
fix(sdl): add static_text flag to to lv_draw_label_dsc_t
... and cache only static texts in the SDL renderer. Otherwise the cached draw_dsc can contain wild pointers if teh texts are reallocated/freed. Fixes #6972
This commit is contained in:
parent
d5b02fe131
commit
780807029f
@ -53,6 +53,11 @@ typedef struct {
|
||||
* < 1: malloc buffer and copy `text` there.
|
||||
* 0: `text` is const and it's pointer will be valid during rendering.*/
|
||||
uint8_t text_local : 1;
|
||||
|
||||
/**
|
||||
* Indicate that the text is constant and its pointer can be safely saved e.g. in a cache.
|
||||
*/
|
||||
uint8_t text_static : 1;
|
||||
lv_draw_label_hint_t * hint;
|
||||
} lv_draw_label_dsc_t;
|
||||
|
||||
|
@ -348,7 +348,6 @@ static void blend_texture_layer(lv_draw_sdl_unit_t * u)
|
||||
|
||||
SDL_Point center = {draw_dsc->pivot.x, draw_dsc->pivot.y};
|
||||
SDL_RenderCopyEx(renderer, src_texture, NULL, &rect, draw_dsc->rotation / 10, ¢er, SDL_FLIP_NONE);
|
||||
// SDL_RenderCopy(renderer, src_texture, NULL, &rect);
|
||||
|
||||
SDL_DestroyTexture(src_texture);
|
||||
SDL_RenderSetClipRect(renderer, NULL);
|
||||
@ -418,10 +417,11 @@ static void draw_from_cached_texture(lv_draw_sdl_unit_t * u)
|
||||
|
||||
lv_cache_release(u->texture_cache, entry_cached, u);
|
||||
|
||||
/*Do not cache label's with local text as the text will be freed*/
|
||||
/*Do not cache non static (const) texts as the text's pointer can be freed/reallocated
|
||||
*at any time resulting in a wild pointer in the cached draw dsc. */
|
||||
if(t->type == LV_DRAW_TASK_TYPE_LABEL) {
|
||||
lv_draw_label_dsc_t * label_dsc = t->draw_dsc;
|
||||
if(label_dsc->text_local) {
|
||||
if(!label_dsc->text_static) {
|
||||
lv_cache_drop(u->texture_cache, &data_to_find, NULL);
|
||||
}
|
||||
}
|
||||
|
@ -783,6 +783,7 @@ static void draw_main(lv_event_t * e)
|
||||
lv_draw_label_dsc_t label_draw_dsc;
|
||||
lv_draw_label_dsc_init(&label_draw_dsc);
|
||||
label_draw_dsc.text = label->text;
|
||||
label_draw_dsc.text_static = label->static_txt;
|
||||
label_draw_dsc.ofs_x = label->offset.x;
|
||||
label_draw_dsc.ofs_y = label->offset.y;
|
||||
#if LV_LABEL_LONG_TXT_HINT
|
||||
|
Loading…
Reference in New Issue
Block a user