The wrong constructor for the OLED display is used in some places, which causes heap corruption (although I don’t understand why).
The Wiki says:
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // OLEDs without Reset of the Display
but the U8x8 docs notes:
“The hardware I2C allows pin remapping for some controller types. The optional pin numbers are listed after the reset pin: ..._HW_I2C([reset [, clock, data]]). Use U8X8_PIN_NONE if the reset input of the display is not connected.
Don’t get confused between hardware I2C pin remapping and software emulated I2C: The constructor for software emulated I2C lists the required clock and data line before the reset pin: ..._SW_I2C(clock, data [, reset])"
and so the correct constructor is:
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA); // OLEDs without Reset of the Display
Making this change solved all my crash issues.