Weird reset behaviour on ESP-EYE when using void function compared to int

Hi, I am getting some strange behaviour that I can't understand. On my esp-eye I am simply calling two functions, with a 2D array as an input. When I call the voidfunc I get this error:

camera initialised
end setup
ets Jun 8 2016 00:22:57

rst:0x8 (TG1WDT_SYS_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:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8

But if I comment out the voidfunc call it works fine (ie returning an int it has no problem with). Also worth noting if I change the size of the array to 2x2 for example it works fine.

#include "esp_camera.h"
#include "esp_timer.h"
#include "img_converters.h"
#include "Arduino.h"
#include "soc/soc.h"           // Disable brownour problems
#include "soc/rtc_cntl_reg.h"  // Disable brownour problems
#include "driver/rtc_io.h"
#include <FS.h>

// ESP-EYE camera module pin-out
#define PWDN_GPIO_NUM    -1
#define RESET_GPIO_NUM   -1
#define XCLK_GPIO_NUM    4
#define SIOD_GPIO_NUM    18
#define SIOC_GPIO_NUM    23

#define Y9_GPIO_NUM      36
#define Y8_GPIO_NUM      37
#define Y7_GPIO_NUM      38
#define Y6_GPIO_NUM      39
#define Y5_GPIO_NUM      35
#define Y4_GPIO_NUM      14
#define Y3_GPIO_NUM      13
#define Y2_GPIO_NUM      34
#define VSYNC_GPIO_NUM   5
#define HREF_GPIO_NUM    27
#define PCLK_GPIO_NUM    25

void setup() {
  // Serial port for debugging purposes
  Serial.begin(115200);

  // Turn-off the 'brownout detector'
  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);

  // ESP-EYE camera module
  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 = 20000000;
  config.pixel_format = PIXFORMAT_GRAYSCALE;
  config.frame_size = FRAMESIZE_QQVGA;
  config.jpeg_quality = 10;
  config.fb_count = 1;
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);

  // Camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    ESP.restart();
  }
  else
  {
    Serial.println("camera initialised");
  }
  Serial.println("end setup");
}


void loop()
{
  Serial.println("start loop");
  uint8_t r[158][118] = {0};
  voidfunc(r);
  //int z = intfunc(r);

}

void voidfunc(uint8_t im[158][118])
{
  Serial.println("void func");
}

int intfunc(uint8_t im[158][118])
{
  Serial.println("int func");
}

The problem is with the way you pass the array to the function.
call like this :

 voidfunc(r,158,118);

and

void voidfunc(uint8_t (*im)[158],n,m)
{
 Serial.println("void func");
}

An example:

#define ROWS 3
#define COLS 2

int array_2D[ROWS][COLS] = { {1, 2}, {3, 4}, {5, 6} };

void setup() {
  Serial.begin(115200);
  while (!Serial);
}

void fun1(int (*a)[COLS], int n, int m)
{
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      Serial.print(i);
      Serial.print("\t");
      Serial.print(j);
      Serial.print("\t");
      Serial.println(a[i][j]);
    }
  }
}

void loop() {
  int n = ROWS;
  int m = COLS;

  fun1(array_2D, n, m);
}

Thank you for that it worked!! Except now when I try and implement this in my program it still resets. It works until the houghtransform function which breaks it. I thought it might be the size (the array inside houghtransform is supposed to be 397x180), but even with a 2x2 I get this problem.

#include "esp_camera.h"
#include "esp_timer.h"
#include "img_converters.h"
#include "Arduino.h"
#include "soc/soc.h"           // Disable brownour problems
#include "soc/rtc_cntl_reg.h"  // Disable brownour problems
#include "driver/rtc_io.h"
#include <FS.h>

#define ROWS 160
#define COLS 120
#define ROW2 158
#define COL2 118
#define WINDOW_SIZE 3
#define PARAM_ROW 2
#define PARAM_COL 2

uint8_t image[ROWS][COLS] = {};

// ESP-EYE camera module pin-out
#define PWDN_GPIO_NUM    -1
#define RESET_GPIO_NUM   -1
#define XCLK_GPIO_NUM    4
#define SIOD_GPIO_NUM    18
#define SIOC_GPIO_NUM    23

#define Y9_GPIO_NUM      36
#define Y8_GPIO_NUM      37
#define Y7_GPIO_NUM      38
#define Y6_GPIO_NUM      39
#define Y5_GPIO_NUM      35
#define Y4_GPIO_NUM      14
#define Y3_GPIO_NUM      13
#define Y2_GPIO_NUM      34
#define VSYNC_GPIO_NUM   5
#define HREF_GPIO_NUM    27
#define PCLK_GPIO_NUM    25

void setup() {
  // Serial port for debugging purposes
  Serial.begin(115200);

  // Turn-off the 'brownout detector'
  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);

  // ESP-EYE camera module
  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 = 20000000;
  config.pixel_format = PIXFORMAT_GRAYSCALE;
  config.frame_size = FRAMESIZE_QQVGA;
  config.jpeg_quality = 10;
  config.fb_count = 1;
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);

  // Camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    ESP.restart();
  }
  else
  {
    Serial.println("camera initialised");
  }
  Serial.println("end setup");
}


//******************************************************* CONVOLVE ***************************************************//
uint8_t** convolve(uint8_t (*im)[COLS], uint8_t rows, uint8_t cols, uint8_t (*window)[WINDOW_SIZE], uint8_t window_size)
{
  uint8_t** return_im = new uint8_t* [ROW2];
  for (uint8_t t = 0; t < ROW2; ++t)
  {
    return_im[t] = new uint8_t [COL2];
  }

  // do some stuff here
  
  return return_im;
}


//***************************************************** SOBEL ****************************************************//
uint8_t** sobel(uint8_t (*im)[COLS], uint8_t rows, uint8_t cols)
{
  Serial.println("sobel");
  uint8_t window_size = WINDOW_SIZE;
  uint8_t Mx[WINDOW_SIZE][WINDOW_SIZE] = { {-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1} };
  uint8_t My[WINDOW_SIZE][WINDOW_SIZE] = { {1, 2, 1}, {0, 0, 0}, {-1, -2, -1} };
  
  uint8_t** arr = new uint8_t* [ROW2];
  for (uint8_t i = 0; i < ROW2; ++i)
  {
    arr[i] = new uint8_t [COL2];
  }

  uint8_t **f = convolve(im, rows, cols, Mx, window_size);

  // do some stuff here

  for (uint8_t i = 0; i < ROW2; ++i)
  {
    delete[] f[i];
  }
  delete[] f;
  

  Serial.println("return from sobel");
  return arr;
}

//*************************************************** HOUGH ****************************************************//
void houghtransform(uint8_t (*im)[COL2], uint8_t n, uint8_t m)
{
  uint8_t** arr2 = new uint8_t* [PARAM_ROW];
  for (uint8_t i = 0; i < PARAM_ROW; i++)
  {
    arr2[i] = new uint8_t [PARAM_COL];
  }

  // do some stuff here

  for (uint8_t i = 0; i < PARAM_ROW; i++)
  {
    delete[] arr2[i];
  }
  delete[] arr2;
}

//**************************************************** LOOP ****************************************************//
void loop()
{
  Serial.println("start loop");
  for (uint8_t x = 0; x < ROWS; x++)
  {
    for (uint8_t y = 0; y < COLS; y++)
    {
      if (50 < x < 60) 
        image[x][y] = 100;
    }
  }  

  uint8_t** edges = sobel(image, ROWS, COLS);

  uint8_t ret[ROW2][COL2] = {0};
  for (uint8_t x = 0; x < 158; x++)
  {
    for (uint8_t y = 0; y < 118; y++)
    {
      ret[x][y] = edges[x][y];
    }
  }

  for (uint8_t i = 0; i < ROW2; ++i)
  {
    delete[] edges[i];
  }
  delete[] edges;

  houghtransform(ret, ROW2, COL2);
}

camera initialised
end setup
ets Jun 8 2016 00:22:57

rst:0x8 (TG1WDT_SYS_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:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8