Procházet zdrojové kódy

Guard shared image buffers against high-resolution overflow

SybexXx před 1 dnem
rodič
revize
b27ca41bd7
1 změnil soubory, kde provedl 11 přidání a 2 odebrání
  1. 11 2
      code/components/jomjol_image_proc/CImageBasis.cpp

+ 11 - 2
code/components/jomjol_image_proc/CImageBasis.cpp

@@ -620,9 +620,18 @@ CImageBasis::CImageBasis(string _name, CImageBasis *_copyfrom)
     }
 
     if (name == "tmpImage") {
-        rgb_image = static_cast<uint8_t*>(psram_reserve_shared_tmp_image_memory());
+        rgb_image = static_cast<uint8_t*>(psram_reserve_shared_tmp_image_memory(imageSize));
         ownsSharedTempImageLease = (rgb_image != NULL);
-        memsize = (rgb_image != NULL) ? static_cast<int>(imageSize) : 0;
+        if (ownsSharedTempImageLease) {
+            memsize = static_cast<int>(imageSize);
+        } else {
+            // High-resolution camera frames can exceed the fixed shared workspace.
+            // Keep the frame in PSRAM heap rather than writing past the shared region.
+            rgb_image = static_cast<uint8_t*>(malloc_psram_heap(
+                std::string(TAG) + "->CImageBasis (" + name + " fallback)", imageSize,
+                MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
+            memsize = (rgb_image != NULL) ? static_cast<int>(imageSize) : 0;
+        }
     } else {
         rgb_image = static_cast<uint8_t*>(malloc_psram_heap(
             std::string(TAG) + "->CImageBasis (" + name + ")", imageSize,