Code: Select all
#include <functional>
typedef std::function<void ()> reqHandler;
reqHandler *l;
void setup() {
Serial.begin(115200);
Serial.printf("Start realloc lambda test ...\n");
l=(reqHandler *) malloc(2*sizeof(reqHandler)); // set 0
Serial.printf("start assign 0 in set 0 l=%0x\n",l);
l[0]=[](){ Serial.printf("lambda 0\n"); };
l[1]=[](){ Serial.printf("lambda 1\n"); };
l=(reqHandler *) realloc(l,4*sizeof(reqHandler)); // set 1
Serial.printf("start assign 2 in set 1 l=%0x\n",l);
l[2]=[](){ Serial.printf("lambda 2\n"); };
l[3]=[](){ Serial.printf("lambda 3\n"); };
l=(reqHandler *) realloc(l,6*sizeof(reqHandler)); // set 2
Serial.printf("start assign 4 in set 2 l=%0x\n",l);
l[4]=[](){ Serial.printf("lambda 4\n"); }; // creates a crash
l[5]=[](){ Serial.printf("lambda 5\n"); };
Serial.printf("... End realloc lambda test.\n");
}
void loop() { }
... creates the following output:
Code: Select all
Start realloc lambda test ...
start assign 0 in set 0 l=3fff086c
start assign 2 in set 1 l=3fff08a4
start assign 4 in set 2 l=3fff08a4
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset
It seems, the realloc function is not working correct. The "cause: 4" (=Level1InterruptCause) seems to make no sense at the point of the code which creates the crash.
I'm using the ardunio IDE 1.6.8 and the ESP8266 Plugin https://github.com/esp8266/Arduino/rele ... -2.3.0.zip. My Hardware is a normal ESP-01 .
The IDE Parameters :
Board: Generic ESP8266 Module
Flash Mode: QIO
Flash Frequenze: 40MHz
CPU Frequenze: 80MHz
Flash Size: 1M (192k SPIFFS)