diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
index c9fe5ba84..ab25c4c88 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/ProfileManagerWidget.cs
@@ -243,7 +243,9 @@ internal class ProfileManagerWidget
if (ImGuiComponents.IconButton(FontAwesomeIcon.Trash))
{
- Task.Run(() => profman.DeleteProfile(profile))
+ // DeleteProfile() is sync, it doesn't apply and we are modifying the plugins collection. Will throw below when iterating
+ profman.DeleteProfile(profile);
+ Task.Run(() => profman.ApplyAllWantStates())
.ContinueWith(t =>
{
this.Reset();
diff --git a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
index 11214ba08..71835a9d6 100644
--- a/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
+++ b/Dalamud/Plugin/Internal/Profiles/ProfileManager.cs
@@ -232,13 +232,16 @@ internal class ProfileManager : IServiceType
}
///
- /// Delete a profile and re-apply all profiles.
+ /// Delete a profile.
///
+ ///
+ /// You should definitely apply states after this. It doesn't do it for you.
+ ///
/// The profile to delete.
public void DeleteProfile(Profile profile)
{
// We need to remove all plugins from the profile first, so that they are re-added to the default profile if needed
- foreach (var plugin in profile.Plugins)
+ foreach (var plugin in profile.Plugins.ToArray())
{
profile.Remove(plugin.InternalName, false);
}
@@ -246,7 +249,6 @@ internal class ProfileManager : IServiceType
Debug.Assert(this.config.SavedProfiles!.Remove(profile.Model), "this.config.SavedProfiles!.Remove(profile.Model)");
Debug.Assert(this.profiles.Remove(profile), "this.profiles.Remove(profile)");
- this.ApplyAllWantStates();
this.config.QueueSave();
}