How to init and toggle led properly?

hey there! i have problems with leds(actually its pointers)

i have an empty global pointers (for example below)

volatile lv_obj_t *led_pointer;

i have init function that looks like

void lv_init_led(lv_obj_t * ledobj,lv_obj_t* par,lv_coord_t x,lv_coord_t y,lv_coord_t sizex,lv_coord_t sizey,char* text_to_the_left,lv_coord_t text_Y_offset)
ledobj  = lv_led_create(par, NULL);
lv_obj_t * label1 = lv_label_create(par, NULL); 

it was made for fast init of bunch of leds.

init sequence works fine, and i can even toggle led in it (in function)
but outside of this function i cant toggle led - program crashes with null-pointer error

Error: lv_led_on        (lv_led.c #131 lv_led_on())
Error: NULL pointer (0x00000000)        (lv_debug.c #127 lv_debug_log_error())

but the same works with buttons and labels and other objects.
What i am douing wrong?

Check that you are not redeclaring the pointer inside the function (shadowing). In your example the global is called led_pointer but you’re assigning the result to ledobj.

it looks like that - also there is no shadowing warnings from gcc…

lv_obj_t* MeanTimesLabelBtn=NULL;
lv_obj_t* F_ABS_LABEL=NULL;
lv_obj_t* UDC_LABEL=NULL;
volatile lv_obj_t *led_1ghz;
volatile lv_obj_t *led_UHF_OK=NULL;
volatile lv_obj_t *led_220V_present=NULL;
volatile lv_obj_t *led_1ghz_out_enabled=NULL;

void createlabels(lv_obj_t* par)
createstyledbutton(MeanTimesLabelBtn,par,labelbtnstyle_pointer,10,10,BUTTON_WIDTH,BUTTON_HEIGHT,"MEAN TIMES",dummybtn_cb);
lv_init_led(led_1ghz,par,460,315,40,40,"1 GHz",-50);
lv_init_led(led_1ghz_out_enabled,par,460,DEFLEDY+55*3,40,40,"1 GHz out",-90);
lv_obj_t * createstyledbutton(lv_obj_t * btn,lv_obj_t * par,lv_style_t* style, lv_coord_t pos_x,lv_coord_t pos_y,lv_coord_t size_wide,lv_coord_t size_height,char btn_text[],lv_event_cb_t event_call_back_function)
btn = lv_btn_create(par, NULL);     /*Add a button the current screen*/
lv_obj_add_style( btn, LV_OBJ_PART_MAIN,style);
lv_obj_align(btn, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_pos(btn,  pos_x,  pos_y);                            /*Set its position*/
lv_obj_set_size(btn,size_wide, size_height);                          /*Set its size*/
lv_obj_set_event_cb(btn, event_call_back_function);                 /*Assign a callback to the button*/
lv_obj_t * label = lv_label_create(btn, NULL);          /*Add a label to the button*/
lv_label_set_text(label, btn_text);                     /*Set the labels text*/
return label;

actually for labels in buttons that i need to change - i am using return value. my daywork ended
i will try to return pointer to global pointer of led tomorrow.

That’s your problem. You are just reassigning the argument passed to the function. This doesn’t change the value outside of the function.

but i am sending argument as a pointer - not as just input value?! in my example i am creating label in function - this may cause problems if i dont save that pointer. but for leds - there are global pointers… cant understand…

ive changed function. seems works well. inside function there is lv_obj_t* led_obj = lv_led_create(par, NULL);

lv_obj_t* lv_init_led(lv_obj_t* par,lv_coord_t x,lv_coord_t y,lv_coord_t sizex,lv_coord_t sizey,char* text_to_the_left,lv_coord_t text_Y_offset);
and it returns pointer on exit.
But i cant understand why it is so…