PlatformIO Community

ESP32 crashes after `framework-arduinoespressif32` update


#1

Hello !
I had a piece of code that yesterday worked without any errors, but now it crashes the ESP.
The only thing I did was to update framework-arduinoespressif32 inside Platformio IDE to @ fd5a2f0.
Commit fd5a2f0 should be this one, right ?

This is the code that previously worked:

//------------------------- fileReadLines()
void fileReadLines(File file, String x[]) {
  int i = 0;
    while(file.available()){
        Serial.println((String)"File size: " + file.size());
        String line= file.readStringUntil('\n');
        line.trim();
        x[i] = line; // This is where it crashes after it reaches x[] limit
        i++;
        logOutput(line);
    }    
}

Stack decoded:

PC: 0x40001432
EXCVADDR: 0xa5a5a5a5

Decoding stack results
0x400e202d: _Unwind_ForcedUnwind_Phase2 at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libgcc/unwind.inc line 175
0x400e2163: _Unwind_RaiseException at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libgcc/unwind.inc line 117
0x400d37d3: _fiprintf_r at ../../../.././newlib/libc/stdio/fiprintf.c line 34
0x400d6145: _svfprintf_r at ../../../.././newlib/libc/stdio/vfprintf.c line 1544
0x400e39df: esp_vfs_register at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/vfs/vfs.c line 122
0x4008865d: xTaskCreatePinnedToCore at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/tasks.c line 841

But I guess that the problem is that the file.size() stays the same, and while(file.available()) goes on until the limit of String x[] is reached and it results, of course, in a crash.

The above statement is wrong. I don’t understand how file.available() works.
I’ve reverted to the “official release” and file.size() value still doesn’t change, but it works.
Even if file.size() doesn’t change, while(file.available()) doesn’t go on and on on an infinite loop. It reads the lines that are inside the file, stores them and exits the while loop.

Additional code

I am reading the file in void setup() and then I pass it to the void fileReadLines() method.
I’m even checking for it’s existence.

//------------------------- logOutput(String)
void logOutput(String string1) {
	circle.push(string1);	
	Serial.println(string1);	
}
//------------------------- fileReadLines()
void fileReadLines(File file, String x[]) {
  int i = 0;
    while(file.available()){
        Serial.println((String)"File size: " + file.size());
        String line= file.readStringUntil('\n');
        line.trim();
        x[i] = line; // This is where it crashes after it reaches x[] limit
        i++;
        logOutput(line);
    }    
}

void setup() {
/*
*
*
*/
  if(!SPIFFS.exists("/inputs.txt")) {
    File inputsCreate = SPIFFS.open("/inputs.txt", "w");
    if(!inputsCreate) logOutput((String)"Couldn't create /inputs.txt");
    logOutput("Was /inputs.txt created ?");
    logOutput(SPIFFS.exists("/inputs.txt") ? "Yes" : "No");
    inputsCreate.close();
    delay(100);
  }
File inputsRead = SPIFFS.open("/inputs.txt");
  if(!inputsRead) logOutput((String)"ERROR ! Couldn't open file to read !");
if(inputsRead.size() > 8) {
    String v[6];
    fileReadLines(inputsRead,v);
}
/*
*
*
*/
}