To use pointer or not to use pointer

Hello dear developers,
I have tested these two codes. One would do its job, the other hangs. I don’t understand why.
The one which works.

    ScreenMain = lv_obj_create( NULL);
    static lv_style_t styleMain;
    lv_style_set_bg_color(&styleMain, lv_color_black());
    lv_obj_add_style(ScreenMain, &styleMain,0);
    lv_scr_load_anim(ScreenMain,LV_SCR_LOAD_ANIM_NONE, 1000, 100, true);

The one which hangs.

    ScreenMain = lv_obj_create( NULL);
    static lv_style_t* styleMain;
    lv_style_set_bg_color(styleMain, lv_color_black());
    lv_obj_add_style(ScreenMain, styleMain,0);
    lv_scr_load_anim(ScreenMain,LV_SCR_LOAD_ANIM_NONE, 1000, 100, true);

The pointer version is just an uninitialized pointer, which will be null in your case. That’s why it crashes.

You mean this is a NULL pointer problem? So what does lv_style_init() do in the pointer version? And why this doesn’t happen in case of objects (widgets)?

In case of static lv_style_t* styleMain; the variable is no initialized. Its value can be 0x0 (NULL), 12873178145, or anything, but most probably something invalid. Therefore lv_style_init tries to initialize the data on an invalid address.
You could do this to make it work:

lv_style_t* styleMain = malloc(sizeof(lv_style_t)); //Now points to an allocated data

lv_obj_t * is always initialized by a “create” function. But in case of styles there is no lv_style_create function because styles are just simple variables not as complicated as widgets.

Thank you @kisvegabor and @embeddedt. It seems I need to dig into the document and code.