Просмотр исходного кода

fix(flow): /doinit reboots instead of rebuilding the flow at runtime

InitFlow() appends new ClassFlow objects to FlowControll without
deleting the old ones, so every /doinit added a second full pipeline:
another raw image (921 KB), AlgROI, ROI images, publishers. When PSRAM
was too small for it the new TakeImage had no image buffer and the next
round panicked; when it fit, every round ran both pipelines and
published two values. The rebuild also ran in the HTTP task while a
round could be using the same objects, the shared tensor arena and the
camera.

The web UI never calls /doinit (config changes reboot), so make the
endpoint do the same: answer and reboot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Victor Gladkikh 1 месяц назад
Родитель
Сommit
e121258f83
1 измененных файлов с 8 добавлено и 5 удалено
  1. 8 5
      code/components/jomjol_flowcontroll/MainFlowControl.cpp

+ 8 - 5
code/components/jomjol_flowcontroll/MainFlowControl.cpp

@@ -23,6 +23,7 @@
 #include "server_GPIO.h"
 
 #include "server_file.h"
+#include "server_ota.h"
 
 #include "read_wlanini.h"
 #include "connect_wlan.h"
@@ -359,14 +360,16 @@ esp_err_t handler_init(httpd_req_t *req)
 #endif
 
     httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
-    const char *resp_str = "Init started<br>";
-    httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
-
-    doInit();
 
-    resp_str = "Init done<br>";
+    // Rebuilding the flow at runtime is not safe: InitFlow() keeps the old ClassFlow objects (a second full
+    // pipeline, ~1.2 MB PSRAM, until allocations fail and the device panics) and races with a running round.
+    // Apply the configuration with a reboot instead.
+    LogFile.WriteToFile(ESP_LOG_INFO, TAG, "/doinit requested -> rebooting to apply the configuration");
+    const char *resp_str = "Reboot to apply the configuration<br>";
     httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
 
+    doReboot();
+
 #ifdef DEBUG_DETAIL_ON
     LogFile.WriteHeapInfo("handler_init - Done");
 #endif