ESP32 crashes after `framework-arduinoespressif32` update

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);
}
/*
*
*
*/
}

I saw they updated File API. Do you use the latest version of dev/platform?

2 Likes

2.5.1 of the ESP8266 brings some major changes to the Filesystem core, so there could be some things broken or implemented differently now… If you had working code, best to stick to the specific version of the core that works for you, or find out what changed.

1 Like

I used to use #feature-stage, but I reverted to the official release and my code works just fine.

That’s what I did.

1 Like

I just did the same myself the other day, as I realised the last few updates introduced some breaking changes, and I don’t want to have to deal with any of those for a while in some of the code I’m still putting together… I’ve got enough of my own bugs to work out before I worry about any that get introduced because of the APIs changing! :laughing:

1 Like

Don’t tell me ! I was just finishing the project and testing it when they changed the filesystem. All of a sudden nothing worked anymore and I had no fcking clue as to why.
I kept telling myself: “But I didn’t change a thing !” …
That’s why I rushed to all the forums I knew.

1 Like