I have found what appears to be a bug - somewhere/somehow when working with large arrays. Below is the smallest test case I've come up with, and I'm not sure where to go from here. Please excuse me if I've done something silly!
The attached generates an array of 2,000 elements, of type "unsigned long" (the same for int, but I think these are the same size on the ESP8266 with Arduino). This is about 8k of RAM, and I should have 40k available for local variables. I have peppered the code with yield() and delay() statements to take that out of the picture. I have tested this only on the WeMos D1 Mini v1 and v2.1.0 (all I have). The attached code reliably crashes the chip. The traceback reason is not consistent, and the stack trace can be very very large.
This was part of a bigger program, but I have cut it right down for the simplest test case I could find.
Some things I have noted:
- If I remove the line Serial.println(tmp);, I don't have any issues.
If I set i=2000 (ie: the size of the array), rather than i=0 on line 31, I don't have any issues.
The thing that's really confusing me is if I uncomment line 34, things work fine. Comment it out, I get a crash. I thought maybe it was because the array was not initialised, hence lines 23-25 (not that it should matter as the memory is allocated by this stage). I have also added a number of extra slots to MAX_SIGNAL_LEN during the deceleration just to be sure (I have no clue what's happening, so trying everything!)
So if anyone has any thoughts, ideas, things I can try, that would be great!
Thanks in advance!
My setup:
- Board: WeMos D1 R2 & mini
CPU Frequency: 80Mhz
Flash Size: "4MB (3MB SPIFFS)