mobile/startup: fix potential crash when switching back and forth

If the user switches away from Subsurface-mobile and back while we are
in our initialization phase, that code might run more than once leading
to undesirable results.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-04-04 14:40:53 -07:00
parent 46c6a3cb92
commit c7c5dac621

View file

@ -308,6 +308,7 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false),
void QMLManager::applicationStateChanged(Qt::ApplicationState state)
{
static bool initializeOnce = false;
QString stateText;
switch (state) {
case Qt::ApplicationActive: stateText = "active"; break;
@ -321,8 +322,9 @@ void QMLManager::applicationStateChanged(Qt::ApplicationState state)
stateText.append((unsavedChanges() ? QLatin1String("") : QLatin1String("no ")) + QLatin1String("unsaved changes"));
appendTextToLog(stateText);
if (state == Qt::ApplicationActive && !m_initialized) {
if (state == Qt::ApplicationActive && !m_initialized && !initializeOnce) {
// once the app UI is displayed, finish our setup and mark the app as initialized
initializeOnce = true;
finishSetup();
appInitialized();
}