Przeglądaj źródła

Bug fix: Failure when cleaning up sites from Login dialog

Source commit: 1a938623538daa6551ad0e353c2effc5cdc15165
Martin Prikryl 6 lat temu
rodzic
commit
1635a26506
1 zmienionych plików z 39 dodań i 32 usunięć
  1. 39 32
      source/forms/Login.cpp

+ 39 - 32
source/forms/Login.cpp

@@ -392,36 +392,40 @@ void __fastcall TLoginDialog::SetNewSiteNodeLabel()
 //---------------------------------------------------------------------
 //---------------------------------------------------------------------
 void __fastcall TLoginDialog::LoadSessions()
 void __fastcall TLoginDialog::LoadSessions()
 {
 {
-  TAutoFlag LoadingFlag(FLoading);
-  SessionTree->Items->BeginUpdate();
-  SessionTree->Images->BeginUpdate();
-  try
   {
   {
-    // optimization
-    SessionTree->SortType = Comctrls::stNone;
+    // Otherwise, once the selected node is deleted, another code is selected and we get failure
+    // while trying to access its data somewhere in LoadContents
+    TAutoFlag LoadingFlag(FLoading);
+    SessionTree->Items->BeginUpdate();
+    SessionTree->Images->BeginUpdate();
+    try
+    {
+      // optimization
+      SessionTree->SortType = Comctrls::stNone;
 
 
-    SessionTree->Items->Clear();
+      SessionTree->Items->Clear();
 
 
-    TTreeNode * Node = SessionTree->Items->AddChild(NULL, L"");
-    Node->Data = FNewSiteData;
-    SetNewSiteNodeLabel();
-    SetNodeImage(Node, NewSiteImageIndex);
+      TTreeNode * Node = SessionTree->Items->AddChild(NULL, L"");
+      Node->Data = FNewSiteData;
+      SetNewSiteNodeLabel();
+      SetNodeImage(Node, NewSiteImageIndex);
 
 
-    DebugAssert(StoredSessions != NULL);
-    for (int Index = 0; Index < StoredSessions->Count; Index++)
+      DebugAssert(StoredSessions != NULL);
+      for (int Index = 0; Index < StoredSessions->Count; Index++)
+      {
+        AddSession(StoredSessions->Sessions[Index]);
+      }
+    }
+    __finally
     {
     {
-      AddSession(StoredSessions->Sessions[Index]);
+      // Restore sorting. Moreover, folders would not be sorted automatically even when
+      // SortType is set (not having set the data property), so we would have to
+      // call AlphaSort here explicitly
+      SessionTree->SortType = Comctrls::stBoth;
+      SessionTree->Images->EndUpdate();
+      SessionTree->Items->EndUpdate();
     }
     }
   }
   }
-  __finally
-  {
-    // Restore sorting. Moreover, folders would not be sorted automatically even when
-    // SortType is set (not having set the data property), so we would have to
-    // call AlphaSort here explicitly
-    SessionTree->SortType = Comctrls::stBoth;
-    SessionTree->Images->EndUpdate();
-    SessionTree->Items->EndUpdate();
-  }
   SessionTree->Selected = SessionTree->Items->GetFirstNode();
   SessionTree->Selected = SessionTree->Items->GetFirstNode();
   UpdateControls();
   UpdateControls();
 }
 }
@@ -732,17 +736,20 @@ void __fastcall TLoginDialog::FormShow(TObject * /*Sender*/)
 void __fastcall TLoginDialog::SessionTreeChange(TObject * /*Sender*/,
 void __fastcall TLoginDialog::SessionTreeChange(TObject * /*Sender*/,
   TTreeNode * /*Node*/)
   TTreeNode * /*Node*/)
 {
 {
-  if (FIncrementalSearching <= 0)
+  if (!FLoading)
   {
   {
-    // Make sure UpdateControls is called here, no matter what,
-    // now it is always called from ResetSitesIncrementalSearch.
-    // For the "else" scenario, UpdateControls is called later from SitesIncrementalSearch.
-    ResetSitesIncrementalSearch();
-  }
+    if (FIncrementalSearching <= 0)
+    {
+      // Make sure UpdateControls is called here, no matter what,
+      // now it is always called from ResetSitesIncrementalSearch.
+      // For the "else" scenario, UpdateControls is called later from SitesIncrementalSearch.
+      ResetSitesIncrementalSearch();
+    }
 
 
-  if (FInitialized)
-  {
-    LoadContents();
+    if (FInitialized)
+    {
+      LoadContents();
+    }
   }
   }
 }
 }
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------