Pitt-RAS / micromouse-2016

7 stars 6 forks source link

Menu hangs on an option #62

Closed ghost closed 7 years ago

ghost commented 8 years ago

Sometimes the menu does not return from an option but instead hangs. Sometimes the selection wheel ends up spinning endlessly, which probably means a motor speed was written, and then the hang prevented further speed settings.

ghost commented 8 years ago

Keeping an eye out to see if c77cb92 changes anything.

ghost commented 7 years ago

Hasn't been observed for a long time.

ghost commented 7 years ago

Aaand it's back.

ghost commented 7 years ago

You wouldn't believe what we found. (It wasn't our fault!)

In the LedDisplay library packaged with teensyduino. In LedDisplay.cpp, in the LedDisplay constructor:

char stringBuffer[displayLength+1]; 

...

this->setString(stringBuffer);

setString() sets a char* member to the given value. So what was happening here is the pointer was being set to an array on the stack. And then the array on the stack was going away when the constructor exited. And then our code was using that memory. And then the library code was writing to what they thought was that array but was actually our memory.

Thank you @amiller27 and @aftersomemath for debugging!! @amiller27 is going to submit a change to upstream.

ghost commented 7 years ago

https://github.com/PaulStoffregen/LedDisplay/pull/2