Skip to content

Canceling tasks at the same moment a timer.every itteration happens causes a crash. #93

@FudgeBot47

Description

@FudgeBot47

Device:
ESP32-S3

I'm using timer.every(1000, increment_timer); to create an incrementing countdown, however there's also a cancel button, which called the default timer.cancel(); , if I press the cancel button at about the same moment as the increment happens, the device crashes with a Guru Meditation Error: Core 1 panic'ed (InstrFetchProhibited). Exception was unhandled. error

Increment Function:

bool increment_timer(void *){
    Serial.println("increment timer called");
    if (glb::ard_timer_seconds > 0){
        glb::ard_timer_seconds--;
    }
    lv_label_set_text(seconds_label, String(glb::ard_timer_seconds).c_str());
    return true;
}

Main button function, with the cancellation code:

static void main_btn_event(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * main_btn = lv_event_get_target(e);
    Serial.println(glb::timer_running);
    Serial.println("main_btn_event called");
    if(code == LV_EVENT_CLICKED) {
        if (glb::timer_running == false){
            glb::timer_running = true;
            glb::ard_timer_seconds = glb::start_timer_seconds;
            near_start();
            Serial.println("started");
            timer.every(1000, increment_timer);
            timer.in(glb::start_timer_seconds * 1000 + 2, leds_off);
            lv_label_set_text(seconds_label, String(glb::start_timer_seconds).c_str());
        }
        else{ 
            ledcWrite(near_led_pin, 0);
            ledcWrite(infrared_led_pin, 0);
            glb::timer_running = false;
            glb::first_time_round = true;
            lv_led_set_brightness(near_led_graphic, graphic_led_off);
            lv_led_set_brightness(infra_led_graphic, graphic_led_off);
            Serial.println("canceled");
            timer.cancel();         <------ Here
            glb::ard_timer_seconds = 0;
            lv_label_set_text(seconds_label, String(glb::ard_timer_seconds).c_str());
            
        }
        
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions