Skip to main content
Associate II
September 21, 2023
Question

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

  • September 21, 2023
  • 1 reply
  • 747 views
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
This topic has been closed for replies.

1 reply

ST Employee
September 22, 2023

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 :grinning_face:

Mohammad MORADIST Software Developer | TouchGFX