I have been getting an exception which I eventually worked out was due to a stack overflow when I had implemented an EEPROM blank check type of sub. The sub is shown here:
As you can see I'm logging the stack buffer usage in the loop and from the logs I can see this increasing by 24 every step until n=168 when the exception is thrown up (and causes a reset of an ESP8266 module in my case). I think I understand that EE.ReadBytes gets a new array each time so I guess that these are just stacking up (though why 24 bytes each time not sure - 12 bytes for each EE.Readbyte). Any views on this and perhaps suggestions for better ways to achieve it? I do know that I can avoid the continual stacking by doing something like x=EE.ReadBytes(n,1)(0) in a second sub which I then call from the above, but this seems like a crude work around arising from my poor underlying understanding.
B4X:
Private Sub Check_EEprom(start As UInt, finish As UInt) As Boolean
Log("Start checking ...")
' Check if any location not cleared to zero
Dim success As Boolean = True
Dim n As UInt
For n=start To finish
Log(n, " ", EE.ReadBytes(n,1)(0))
Log("stack: ", StackBufferUsage)
If EE.ReadBytes(n,1)(0) <> 0 Then success = False
Next
Log("EEPROM check result: ",success)
Return success
End Sub
As you can see I'm logging the stack buffer usage in the loop and from the logs I can see this increasing by 24 every step until n=168 when the exception is thrown up (and causes a reset of an ESP8266 module in my case). I think I understand that EE.ReadBytes gets a new array each time so I guess that these are just stacking up (though why 24 bytes each time not sure - 12 bytes for each EE.Readbyte). Any views on this and perhaps suggestions for better ways to achieve it? I do know that I can avoid the continual stacking by doing something like x=EE.ReadBytes(n,1)(0) in a second sub which I then call from the above, but this seems like a crude work around arising from my poor underlying understanding.
Last edited: