dlbeer / quirc

QR decoder library
Other
882 stars 286 forks source link

Stack overflow error on ESP32 #131

Open Duvio opened 1 year ago

Duvio commented 1 year ago

When i upload this code to the ESP32 i get an stack overflow error

#include "esp_camera.h"
#include <WiFi.h>

#include <quirc.h>

#define CAMERA_MODEL_AI_THINKER
#include "camera_pins.h"

void setup() {
  Serial.begin(115200);
  Serial.println();

  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 10000000;
  config.frame_size = FRAMESIZE_QVGA;
  config.pixel_format = PIXFORMAT_GRAYSCALE;
  config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
  config.fb_location = CAMERA_FB_IN_PSRAM;
  config.jpeg_quality = 10;
  config.fb_count = 2;
  config.grab_mode = CAMERA_GRAB_LATEST;

  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x\n", err);
  }

  Serial.println("Camera initialized");
  sensor_t* s = esp_camera_sensor_get();
  Serial.println("Retrieved sensor");
}

void loop() {
  struct quirc *qr;
  qr = quirc_new();
  if(!qr) {
    Serial.println("Failed to allocate memory");
    delay(1000000);
  } else {
    Serial.println("Allocated memory");
  }
  if(quirc_resize(qr, 320, 240) < 0) {
    Serial.println("Failed to allocate video memory");
    delay(1000000);
  } else {
    Serial.println("Allocated video memory");
  }
  Serial.println(0);
  uint8_t *image;
  Serial.println(1);
  int w, h;
  Serial.println("Before quirc_begin");
  image = quirc_begin(qr, &w, &h);
  Serial.println("After quirc_begin");
  camera_fb_t* fb = esp_camera_fb_get();
  if (!fb) {
    Serial.println("Camera Capture Failed");
  }
  memcpy(image, fb->buf, fb->len);
  quirc_end(qr);
  if(quirc_count(qr)>0) {
    struct quirc_code code;
    struct quirc_data data;
    quirc_decode_error_t err;

    quirc_extract(qr, 0, &code);

    err = quirc_decode(&code, &data);
    //Serial.write(data.payload, data.payload_len);
  }
  esp_camera_fb_return(fb);
  quirc_destroy(qr);
}

This is the output

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13864
load:0x40080400,len:3608
entry 0x400805f0

Camera initialized
Retrieved sensor
Allocated memory

***ERROR*** A stack overflow in task loopTask has been detected.

Backtrace:0x400837e9:0x3ffaf3500x40089dad:0x3ffaf370 0x4008c975:0x3ffaf390 0x4008b6bf:0x3ffaf410 0x40089ebc:0x3ffaf440 0x40089e6c:0x89362c2e  |<-CORRUPTED

ELF file SHA256: 0000000000000000

Rebooting...

Can you help me solve this?

Duvio commented 1 year ago

Hey @MU-Software, i have seen your pull request and used your version instead, but it still gives me same error

JoseSilva23 commented 3 months ago

i have a similar issue did u find a solution for it @Duvio?