Repository: microsoft/terminal (language: cpp)

Issue:
Deleting a (last?) profile in the SUI sends the Terminal to a farm upstate
1. Make a new blank profile
2. Save the settings
3. Head over to	that "delete profile" button and hit it
4. [**ZOOP**](https://www.oocities.org/~robink/zoop.jpg), no Terminal


Stack was useless - something above a `DispatcherLoop` with a `ReportUnhandledError` about a "The application attempted to access data outside the valid range" but I apparently don't have `!xamlstowed` installed anymore.
Deleting a (last?) profile in the SUI sends the Terminal to a farm upstate
1. Make a new blank profile
2. Save the settings
3. Head over to	that "delete profile" button and hit it
4. [**ZOOP**](https://www.oocities.org/~robink/zoop.jpg), no Terminal


Stack was useless - something above a `DispatcherLoop` with a `ReportUnhandledError` about a "The application attempted to access data outside the valid range" but I apparently don't have `!xamlstowed` installed anymore.


Discussion / hints:
I cannot repro this on current main nor on preview (1.14.891.0). Do you consistently hit this or only sometimes?
Okay, got it to hit the _second_ time I tried this. First time, no repro. Second time, I made the Terminal wide enough that the nav view was in its expanded state, and then the terminal died on the delete.
Gosh I can't find it now, but we had some crash in the past about changing the elements of a nav view. Something about the vector of items.... @carlos-zamora  do you remember what I'm thinking of?
THIS ONE 
#8773


Oh my god it's the same: #8747
```c++
        // Add an event handler for when the user wants to delete a profile.
        profile.DeleteProfile({ this, &MainPage::_DeleteProfile });
```


I'd bet we're adding the delete handler TWICE. Stepping through `MainPage::_DeleteProfile`, the first time it succeeds, but then there's a SECOND call to that handler. Why is there a second call? That's not right.


It might mean that the repro is
1. Make a new blank profile
2. Save the settings
3. Click on the profile ABOVE the new profile
4. Click back to the new profile
5. Head over to	that "delete profile" button and hit it
6. [**ZOOP**](https://www.oocities.org/~robink/zoop.jpg), no Terminal
I cannot repro this on current main nor on preview (1.14.891.0). Do you consistently hit this or only sometimes?
Okay, got it to hit the _second_ time I tried this. First time, no repro. Second time, I made the Terminal wide enough that the nav view was in its expanded state, and then the terminal died on the delete.
Gosh I can't find it now, but we had some crash in the past about changing the elements of a nav view. Something about the vector of items.... @carlos-zamora  do you remember what I'm thinking of?
THIS ONE 
#8773


Oh my god it's the same: #8747
```c++
        // Add an event handler for when the user wants to delete a profile.
        profile.DeleteProfile({ this, &MainPage::_DeleteProfile });
```


I'd bet we're adding the delete handler TWICE. Stepping through `MainPage::_DeleteProfile`, the first time it succeeds, but then there's a SECOND call to that handler. Why is there a second call? That's not right.


It might mean that the repro is
1. Make a new blank profile
2. Save the settings
3. Click on the profile ABOVE the new profile
4. Click back to the new profile
5. Head over to	that "delete profile" button and hit it
6. [**ZOOP**](https://www.oocities.org/~robink/zoop.jpg), no Terminal

Fix patch:
diff --git a/.github/actions/spelling/allow/allow.txt b/.github/actions/spelling/allow/allow.txt
index 37a5b7d0f28..60b57274c84 100644
--- a/.github/actions/spelling/allow/allow.txt
+++ b/.github/actions/spelling/allow/allow.txt
@@ -38,6 +38,7 @@ hostnames
 hyperlink
 hyperlinking
 hyperlinks
+iconify
 img
 inlined
 It'd
diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.cpp b/src/cascadia/TerminalSettingsEditor/MainPage.cpp
index ed3ca9e4cea..5bb04d603de 100644
--- a/src/cascadia/TerminalSettingsEditor/MainPage.cpp
+++ b/src/cascadia/TerminalSettingsEditor/MainPage.cpp
@@ -419,9 +419,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
 
         _PreNavigateHelper();
 
-        // Add an event handler for when the user wants to delete a profile.
-        profile.DeleteProfile({ this, &MainPage::_DeleteProfile });
-
         _SetupProfileEventHandling(state);
 
         contentFrame().Navigate(xaml_typename<Editor::Profiles_Base>(), state);
@@ -566,6 +563,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
                 }
             }
         });
+
+        // Add an event handler for when the user wants to delete a profile.
+        profile.DeleteProfile({ this, &MainPage::_DeleteProfile });
+
         return profileNavItem;
     }
 


Test patch: