File tree Expand file tree Collapse file tree
firmware/main/modules/animations_task Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ static void animations_task(void* pvParameters) {
1818 }
1919 vTaskDelay (pdMS_TO_TICKS (delay_ms ));
2020 }
21+ // Clear handle before self-delete so animations_task_stop() knows we exited.
22+ animations_task_handle = NULL ;
2123 vTaskDelete (NULL );
2224}
2325
@@ -36,6 +38,19 @@ void animations_task_run(void* animation_cb,
3638void animations_task_stop () {
3739 animations_task_cb = NULL ;
3840 running = false;
41+ if (animations_task_handle == NULL ) {
42+ return ;
43+ }
44+ // Wait for the task to finish its current OLED/I2C frame and exit naturally.
45+ // Force-killing with vTaskDelete() while the task holds oled_mutex causes a
46+ // permanent deadlock: the mutex is never released, blocking every subsequent
47+ // OLED call (including sniffer_task's display update), which in turn blocks
48+ // sniffer_stop()'s sem_task_over wait — resulting in a full system freeze.
49+ uint8_t retries = 30 ; // 30 × 10 ms = 300 ms max
50+ while (animations_task_handle != NULL && retries -- > 0 ) {
51+ vTaskDelay (pdMS_TO_TICKS (10 ));
52+ }
53+ // Safety net: if the task is still alive after 300 ms, force-delete.
3954 if (animations_task_handle != NULL ) {
4055 vTaskDelete (animations_task_handle );
4156 animations_task_handle = NULL ;
You can’t perform that action at this time.
0 commit comments