How to reset task

Description

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

codeblocks-20.03mingw

hello, I want to create a task that calls a function (home_open1()) (until now it works) then reinitialize the task at each call to the function (home_open()).
the code is compiled but the app crashes during the second call of the function (home_open() )
ps : the function home_open1 () create screensaver.

Code to reproduce

static void task_cb(lv_task_t * task);
static lv_task_t * task;
bool taskk = false  ;

static void task_cb(lv_task_t * task)
{  
      home_open1(0);
};
/* I TRIED */ 
static  void home_open(uint32_t delay) {

  if (taskk ) {
lv_task_reset(task);
  } else {
lv_task_t * task = lv_task_create(task_cb, 10000, LV_TASK_PRIO_MID, NULL);
taskk = true ; 
  }

``
}`
/* I TRIED */
static  void home_open(uint32_t delay) {

  if (taskk ) {
 lv_task_del(task);
lv_task_t * task = lv_task_create(task_cb, 10000, LV_TASK_PRIO_MID, NULL);
  } else {
lv_task_t * task = lv_task_create(task_cb, 10000, LV_TASK_PRIO_MID, NULL);
taskk = true ; 
  }

``
}`

You’ve declared task as a global variable and then redeclared it inside the function.

The calls to lv_task_reset and lv_task_del use the global variable, but it never gets initialized, since lv_task_create's return value is stored in a local variable.

its works thank youuuu :muscle: