cancel
Showing results for 
Search instead for 
Did you mean: 

OK to call gotoXYZScreenoTransition() from Model tick()?

da66en
Associate II
Is it OK to call one of the app()->gotoXYZScreenoTransition() functions from inside the Model tick()?

The reason I'm asking is that I just got a weird exception on this code that is inside Model tick():

case (newData)
{
    if (modelListener != 0)
    {
        modelListener->notifyDataChanged();
    }
}

Exception was when it was calling the notifyDataChanged().  There wore 2 more items on the stack, but Visual Studio didn't know to decode them so they were just an address in the call stack.  Either something in my code corrupted the modelListener and it was pointing to a bad value, or I called gotoXYZScreenoTransition() when I shouldn't have it changed the modelListener value while I was in the middle of calling it.

I got the idea for the above from
1 REPLY 1

Hello @da66en ,

The Model class is used for propagating data between different screens or between the UI and the hardware. Screen transitioning should be handled from the UI, therefore, you should not call it from the Model. Instead, you need to implement the 'notifyDataChanged' in the proper screen Presenter and call a function from the screen which does the transition. You can't call the transition directly from the Presenter, because application() is a protected member of the Screen class.
Bottom line, you need a chain of calls like this:
Model -> modelListener -> Presenter -> Screen 

I hope this helps you, and feel free to ask more questions

Mohammad MORADI
ST Software Developer | TouchGFX