Bug? Strings and Bytes Quiz Crashes ESP32?

miker2069

Active Member
Licensed User
So after a long break, I'm resuming some B4R projects and typically I like to refresh my memory on string usage on the platform (since that's the thing that usually gets me in trouble on ESPs). I have a ESP32 with built in OLED board and I was trying the Strings and Bytes quiz which basically asks what's the output of the last line of the following:

B4X:
Private Sub AppStart
  Serial1.Initialize(115200)
  Log("AppStart")
  Dim bc As ByteConverter
  Dim b() As Byte = bc.Trim("abcdef ")
  b(0) = Asc("M") 'this line will change the value of the literal string
  Dim s As String = "abcdef "
  Log(s) 'Mbcdef
  Log("abcdef ") '???
End Sub
So using a basic B4R program and just copying and pasting this code and running it on my ESP32 OLED board - it crashes. Note, I've been using this board with other test programs and it works fine...Running this particular code block crashes it every time. I plugged in a WEMOS D1 MINI ESP8266 to make sure it wasn't my computer or something funky with my B4R setup - the ESP8266 works. Puzzling. Thinking maybe the ESP32 OLED board I have might be bad, I found a generic ESP32 WROVER dev board and tried it on that - it crashes that too. So my conclusion it works for ESP8266 and not for ESP32 boards? So it seems like something weird is going on with this on ESP32? I added some additional logs like so:

B4X:
Private Sub AppStart
    Serial1.Initialize(115200)
    Delay(5000)
    Log("AppStart")
    Dim bc2 As ByteConverter
    Log("Point 1")
  
    Dim b() As Byte = bc2.Trim("abcdef ")
    Log("Point 2")
    b(0) = Asc("M") 'this line will change the value of the literal string
    Log("Point 3")
    Dim s As String = "abcdef "
    Log("Point 4")
  
    Log(s) 'Mbcdef
    Log("Point 5")
  
    Log("abcdef ") '???
    Log("Point 6")
End Sub
And it crashes at this line everytime:
B4X:
    b(0) = Asc("M") 'this line will change the value of the literal string
Looks like however the ESP32 core deals with allocating memory for "abcdef " causes it to crash (probably it fails on ESP8266 as well just doesn't throw any errors). Anyway, I thought I'd post this quirk here.
 
Top