-->
Page 1 of 2

getting Stacktrace error in serial monitor please help

PostPosted: Sun May 31, 2020 5:43 am
by seaurchin
I decoded the ESP8266 stacktrace I was getting in serial monitor:

Code: Select allDecoding stack results
0x40211de4: operator new[](unsigned int) at ../../../../../dl/gcc-xtensa/libstdc++-v3/libsupc++/new_opv.cc line 33
0x40202219: SensorData::read_sensor_data::analogValues() at /var/folders/43/m1qv9zf53q19sqh6h9kg9pz80000gn/T/arduino_build_623045/sketch/read_sensor_data.cpp line 19
0x402022cc: loop() at /Users/seaurchin/Development/Arduino/wemos/soil_sensor_with_ads/soil_sensor_with_ads.ino line 21
0x40207b24: loop_wrapper() at /Users/seaurchin/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/core_esp8266_main.cpp line 125


Looks like its pointing to this library read_sensor_data.cpp

Code: Select all#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include "read_sensor_data.h"

Adafruit_ADS1115 ads;

namespace SensorData
{
void read_sensor_data::initializeADC() {
  ads.setGain(GAIN_TWOTHIRDS);
  ads.begin();
}

int* read_sensor_data::analogValues()
  {
 
      int* arr = new int[4];
      int16_t adc0, adc1, adc2, adc3;
      arr[0] = ads.readADC_SingleEnded(0);
      arr[1] = ads.readADC_SingleEnded(1);
      arr[2] = ads.readADC_SingleEnded(2);
      arr[3] = ads.readADC_SingleEnded(3);
      return arr;
  }

}


but I do not understand what is wrong here. :roll:

Re: getting Stacktrace error in serial monitor please help

PostPosted: Sun May 31, 2020 6:10 am
by Pablo2048
Maybe it's OOM - are you freeing arr array, which is allocated by new() after use?

Re: getting Stacktrace error in serial monitor please help

PostPosted: Sun May 31, 2020 7:06 am
by seaurchin
Well no, didnt thought about it. :?
how should I do that ?

Re: getting Stacktrace error in serial monitor please help

PostPosted: Sun May 31, 2020 7:42 am
by Pablo2048
Every call to read_sensor_data::analogValues() return pointer to newly allocated int[4] array, so you have to free the memory when you are done with the values from this array so take a look at this https://www.geeksforgeeks.org/delete-in-c/ .