Can't add userdata to event callback


I would like to add userdata to the event. However, the user data is always transmitted incorrectly.

What MCU/Processor/Board and compiler are you using?

Arduino Due / Arduino IDE

What LVGL version are you using?


What do you want to achieve?

The user data correctly transferred to the event callback function

What have you tried so far?

I tried to transfer user data via LVGL functions. When reading out the data does not match the original data that I sent. I send an Integer like 10001 but when i print the receive userdata it is something like 5344554.

Code to reproduce

The code block(s) should be formatted like:

          int tmp_numpad_userdata;
          tmp_numpad_userdata = channel * 10000 + current_frame * 100 + current_signal;
 lv_obj_add_event_cb(labelReihe1[current_signal + output_config_send_data_offset][1], my_event_cb_NUM_Pad, LV_EVENT_CLICKED, &tmp_numpad_userdata); 

// and the cb function

static void my_event_cb_NUM_Pad(lv_event_t * e)
  int * userdata = (int *)lv_event_get_user_data(e);
  //int userdata2 = int(*userdata)
  //int *pInt = static_cast<int*>(lv_event_get_user_data(e));
  log_item("Übergabeparameter ist  ");
  log_item(* userdata);

What is

int tmp_numpad_userdata;

Is this local or global variable?

Oh yeah sry for this. It’s a local Variable.

What if you made it global or static local?

The solution is to declare the userdata to be transferred as a define.
If i want transfer a struct as userdata i have to do it that way:

struct TMP_numpad_userdata
    byte channel;
    byte frame;
    byte signaL;

 typedef TMP_numpad_userdata  lv_obj_user_data_t; 

Now i can use this struct to transfer userdata.