Closed sauvant closed 2 years ago
@sauvant, thank you for the issue. Good catch!
Unfortunately, the last change in Point has broken passing by value.
You can work around this using passing by reference, which is recommended way for objects. The only change you need is:
void func_2(Point &new_point) {
Steps to reproduce: List the minimal actions needed to reproduce the behavior.
Compile and execute this code:
include
include
void func_2(Point new_point) { Serial.println(new_point.toLineProtocol()); }
void func_1() { Point new_point("test"); new_point.addField("testfield", 1); Serial.println(new_point.toLineProtocol()); func_2(new_point); }
void setup() { Serial.begin(115200); }
void loop() { func_1(); delay(1000); }
Expected behavior: Would like to see two times the line protocol per iteration
Actual behavior: ESP32 resets with "CORRUPT HEAP" fault. Backtrace:
Decoding stack results 0x40083a99: panic_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/panic.c line 402 0x4008e65d: esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/esp_system.c line 128 0x40093911: __assert_func at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/assert.c line 85 0x40093557: multi_heap_free at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c line 245 0x40083efd: heap_caps_free at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c line 340 0x40093941: free at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/heap.c line 39 0x40156725: operator delete(void) at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/del_op.cc line 49 0x40156cd5: operator delete[](void) at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/del_opv.cc line 35 0x400d3a83: Point::~Point() at .pio/libdeps/release/ESP8266 Influxdb/src/Point.cpp line 39 0x400df57a: ELStatus::persist_status(el_status_record) at .pio/libdeps/release/ESP8266 Influxdb/src/Point.h line 38 0x400df63e: ELStatus::loop() at lib/ELStatus/ELStatus.cpp line 70 0x400d2f02: loop() at src/main.cpp line 34 0x400e2681: loopTask(void*) at C:/Users/adiksauvan/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp line 50
Specifications:
Am I missing something? Is this a stupid question? ;-) I know: passing objects by value is not a good idea in most cases. But I would like to understand, why it fails to hard here. Thanks for any advice!
Keith