jonblack / arduino-menusystem

Arduino library for implementing a menu system
MIT License
194 stars 85 forks source link

prev, next, back don't work on Due #72

Closed rocketbob closed 6 years ago

rocketbob commented 6 years ago

I noticed a previous bug that was closed for a similar issue I'm having on the Due. I can display a menu just fine but when calling prev(), next(), or back() my Arduino Due hangs.

I've narrowed it down to hanging on the following line, when calling next: return _p_curr_menu->_p_current_component->next(loop);

It blows up on this line. I've put a Serial.println and commented out all of the next method's code and it never makes it to that point. So it blows up on this line, but its odd because the if statement works fine.

My menu code is per the examples, and I've commented out code out of my render methods to isolate them.

Do you have any suggestions on how to debug this?

My menu initialization code:

static bool runOnce = false;
    if (!runOnce) {
        MenuItem m1("test1", &test1Selected);
        MenuItem m2("test2", &test2Selected);
        MenuItem m3("test3", &test3Selected);
        MenuItem m4("test4", &test4Selected);

        ms.get_root_menu().add_item(&m1);
        ms.get_root_menu().add_item(&m2);
        ms.get_root_menu().add_item(&m3);
        ms.get_root_menu().add_item(&m4);
        runOnce = true;
    }
    ms.display(); 
rocketbob commented 6 years ago

Removing the if statement, and the offending line, makes it work.

So if I change next to look like this, it works:

bool MenuSystem::next(bool loop) {
    if (_p_curr_menu->_p_current_component->has_focus())
        return _p_curr_menu->next(loop);
}
rocketbob commented 6 years ago

This seems to be more reliable:

bool MenuSystem::next(bool loop) { return _p_curr_menu->next(loop); }

rocketbob commented 6 years ago

Thinking about why this bandaid is working....possible that something funky is going on with the realloc call in add_component.

rocketbob commented 6 years ago

Please close, I figured out my issue. Nothing amiss with the library!