interesting lcd.print memory bug

sebasdt
Posts: 17
Joined: Fri Jul 24, 2020 8:18 am

interesting lcd.print memory bug

Postby sebasdt » Wed Jan 06, 2021 9:46 am

I have an interesting bug in my code.
First a little background I'm trying to make a "simple" menu system together with freeRTOS, an encoder and an I2C LCD (16x2).

I have a string array just sitting there in the code doing nothing. Somehow it's printed to the LCD.
Never does Lcd.print make a call to that string.
here below is the sting on line 44 - 46.

Code: Select all

const int numOfSettingsBox = 7  ;
String settings[numOfSettingsBox] = {{"Choose Mode:"}, {"Brightness:"}, {"Back"}, {"Brightness:"}, {"Sensitivity"},  {"Reacts on:"},  {"Back"},
};
Then I thought well let's remove this string and when that bug happens t esp32 crashes with a LoadProhibited fault.
I know what this error means (it means you can't read this bit of memory) so think this is just the way I send the data out to the lcd.

I have uploaded the code to Github https://github.com/sebasdt/BUGS/tree/ma ... ystem_test and here is a video what happens https://youtu.be/LcgOLV3JvBM.

thank you for the help in advance.

boarchuz
Posts: 606
Joined: Tue Aug 21, 2018 5:28 am

Re: interesting lcd.print memory bug

Postby boarchuz » Wed Jan 06, 2021 10:48 am

The raw encoder value is ultimately being used as the index for array Keuzes, without any checking. If it isn't conveniently 0, 1, or 2 then all bets are off.

Whatever value it was (-1?) just happened to be the offset to one of the pointers ("Back"?) in your other 'unused' array.

sebasdt
Posts: 17
Joined: Fri Jul 24, 2020 8:18 am

Re: interesting lcd.print memory bug

Postby sebasdt » Fri Jan 08, 2021 8:26 pm

boarchuz wrote:
Wed Jan 06, 2021 10:48 am
The raw encoder value is ultimately being used as the index for array Keuzes, without any checking. If it isn't conveniently 0, 1, or 2 then all bets are off.
thanks for the tip! I overshot the index of the array. and have fixed it

Who is online

Users browsing this forum: No registered users and 89 guests