From 4ad02938c89f8df09bdae3e566cd62cb3bf17f08 Mon Sep 17 00:00:00 2001
From: dt <qtc-committer@nokia.com>
Date: Thu, 3 Jun 2010 13:55:16 +0200
Subject: [PATCH] Fix crash on session restore

Do the project restore for each project directly after opening and only
then processEvents(). A project might be in a intermediate state between
opening and restoring.
---
 .../projectexplorer/projectexplorer.cpp       | 53 +++++++------------
 1 file changed, 18 insertions(+), 35 deletions(-)

diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index bf5ee338603..893ddd4120e 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -1014,54 +1014,37 @@ QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileName
     ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
     QList<IProjectManager*> projectManagers = pm->getObjects<IProjectManager>();
 
-    //QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
-   // bool blocked = blockSignals(true);
     QList<Project*> openedPro;
     foreach (const QString &fileName, fileNames) {
         if (const Core::MimeType mt = Core::ICore::instance()->mimeDatabase()->findByFile(QFileInfo(fileName))) {
-            foreach (IProjectManager *manager, projectManagers)
+            foreach (IProjectManager *manager, projectManagers) {
                 if (manager->mimeType() == mt.type()) {
-                    if (Project *pro = manager->openProject(fileName))
-                        openedPro += pro;
+                    if (Project *pro = manager->openProject(fileName)) {
+                        if (pro->restoreSettings()) {
+                            connect(pro, SIGNAL(fileListChanged()), this, SIGNAL(fileListChanged()));
+                            d->m_session->addProject(pro);
+                            // Make sure we always have a current project / node
+                            if (!d->m_currentProject && !openedPro.isEmpty())
+                                setCurrentNode(pro->rootProjectNode());
+                            openedPro += pro;
+                        } else {
+                            delete pro;
+                        }
+                    }
                     d->m_session->reportProjectLoadingProgress();
                     break;
                 }
+            }
         }
     }
-    //blockSignals(blocked);
+    updateActions();
 
     if (openedPro.isEmpty()) {
-        if (debug)
-            qDebug() << "ProjectExplorerPlugin - Could not open any projects!";
-        QApplication::restoreOverrideCursor();
-        return QList<Project *>();
-    }
-
-    QList<Project *>::iterator it, end;
-    end = openedPro.end();
-    for (it = openedPro.begin(); it != end; ) {
-        if (debug)
-            qDebug()<<"restoring settings for "<<(*it)->file()->fileName();
-        if ((*it)->restoreSettings()) {
-            connect(*it, SIGNAL(fileListChanged()), this, SIGNAL(fileListChanged()));
-            ++it;
-        } else {
-            delete  *it;
-            it = openedPro.erase(it);
-        }
+        qDebug() << "ProjectExplorerPlugin - Could not open any projects!";
+    } else {
+        Core::ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT);
     }
 
-    d->m_session->addProjects(openedPro);
-
-    // Make sure we always have a current project / node
-    if (!d->m_currentProject && !openedPro.isEmpty())
-        setCurrentNode(openedPro.first()->rootProjectNode());
-
-    updateActions();
-
-    Core::ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT);
-    QApplication::restoreOverrideCursor();
-
     return openedPro;
 }
 
-- 
GitLab