From 728cd172752a5b123353e1c0cdc5c6b455b3b04a Mon Sep 17 00:00:00 2001 From: manison Date: Tue, 12 Feb 2019 09:04:24 +0100 Subject: [PATCH] determine required size of the th_styles array at compile time and remove runtime assertion https://github.com/littlevgl/lvgl/issues/806 --- lv_themes/lv_theme.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lv_themes/lv_theme.c b/lv_themes/lv_theme.c index 2090529f6..bbdca6e4c 100644 --- a/lv_themes/lv_theme.c +++ b/lv_themes/lv_theme.c @@ -34,10 +34,8 @@ static lv_theme_t * current_theme; * This way the theme styles will always point to the same memory address even after theme is change. * (The pointers in the theme points to the styles declared by the theme itself) */ -/* Store the styles in this array. - * Can't determine the size in compile time because sizeof is not evaluated (should be `sizeof(lv_theme_t) / sizeof(lv_style_t*)`). - * Error will be generated in run time if too small.*/ -static lv_style_t th_styles[120]; +/* Store the styles in this array. */ +static lv_style_t th_styles[sizeof(((lv_theme_t *)0)->style) / sizeof(lv_style_t *)]; static bool inited = false; static lv_theme_t current_theme; #endif @@ -63,12 +61,6 @@ void lv_theme_set_current(lv_theme_t * th) uint32_t style_num = sizeof(th->style) / sizeof(lv_style_t *); /*Number of styles in a theme*/ if(!inited) { - /*It's not sure `th_styles` is big enough. Check it now!*/ - if(style_num > sizeof(th_styles) / sizeof(lv_style_t)) { - LV_LOG_ERROR("Themes: th_styles array is too small. Increase it's size!"); - while(1); - } - /*Initialize the style pointers `current_theme` to point to the `th_styles` style array */ uint16_t i; lv_style_t ** cur_th_style_p = (lv_style_t **) ¤t_theme.style;