Disappearing user data

need help. What am I doing wrong?

my code:

static lv_obj_t *main_scr;
static lv_group_t *main_group;
static lv_obj_t *model_choise; 
static lv_obj_t *rssi_level;

	main_group = lv_group_create();
	main_scr = create_main_screen(main_group);

static lv_obj_t* create_main_screen(lv_group_t *group)

	lv_obj_t *screen = lv_obj_create(NULL, NULL);

	model_choise = lv_roller_create(screen, NULL);
	lv_roller_set_options(model_choise, "Audi\nMercedes\nOpel\nVolvo\nVW", LV_ROLLER_MODE_INIFINITE);
	lv_roller_set_visible_row_count(model_choise, 2);
	//lv_roller_set_fix_width(model_choise, 0);
	lv_obj_align(model_choise, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
	lv_obj_set_event_cb(model_choise, model_choise_event_cb);
	lv_group_add_obj(group, model_choise);

	rssi_level = lv_bar_create(screen, NULL);
	lv_obj_set_size(rssi_level, 40, 10);
	lv_bar_set_range(rssi_level, 0, 31);
	lv_obj_align(rssi_level, NULL, LV_ALIGN_IN_TOP_LEFT, 10, 10);
	lv_obj_set_user_data(rssi_level, 2); /* Store the next screen ID in user data */
	lv_obj_set_event_cb(rssi_level, screen_swith);
	lv_group_add_obj(group, rssi_level);

	return screen;

static void screen_swith(lv_obj_t *obj, lv_event_t event)
//user data  lose ???????

Can you confirm that the same object is passed to screen_swith? Is LV_USE_USER_DATA enabled in lv_conf.h?

Yes, rssi_level is passed to screen_swith.
If LV_USE_USER_DATA were disabled, I would get a compilation error.

Any ideas?

I wanted to reproduce it but don’t know when the screen_swith is called from the bar.

What is lv_obj_user_data_t in lv_conf.h?

static void screen_swith(lv_obj_t* obj, lv_event_t event)
	if (event == LV_EVENT_PRESSED)
/*Declare the type of the user data of object (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_obj_user_data_t;


i found problem. Its my mistake :frowning: when i copied part of code forgot to change obj in lv_obj_set_user_data. Sorry.

P.S. duck debugging still the best :wink:


1 Like