diff options
-rw-r--r-- | docs/release-notes.md | 4 | ||||
-rw-r--r-- | src/SMAPI/Framework/Events/ManagedEventBase.cs | 7 |
2 files changed, 8 insertions, 3 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md index 3dee3705..35f711fb 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,4 +1,8 @@ # Release notes +## 2.5.1 +* For players: + * Fixed event error in rare cases. + ## 2.5 * For players: * **Added support for [content packs](https://stardewvalleywiki.com/Modding:Content_packs)**. diff --git a/src/SMAPI/Framework/Events/ManagedEventBase.cs b/src/SMAPI/Framework/Events/ManagedEventBase.cs index cc4d89ec..7e42d613 100644 --- a/src/SMAPI/Framework/Events/ManagedEventBase.cs +++ b/src/SMAPI/Framework/Events/ManagedEventBase.cs @@ -55,7 +55,7 @@ namespace StardewModdingAPI.Framework.Events protected void AddTracking(TEventHandler handler, IEnumerable<TEventHandler> invocationList) { this.SourceMods[handler] = this.ModRegistry.GetFromStack(); - this.CachedInvocationList = invocationList.ToArray(); + this.CachedInvocationList = invocationList?.ToArray() ?? new TEventHandler[0]; } /// <summary>Remove tracking for an event handler.</summary> @@ -63,8 +63,9 @@ namespace StardewModdingAPI.Framework.Events /// <param name="invocationList">The updated event invocation list.</param> protected void RemoveTracking(TEventHandler handler, IEnumerable<TEventHandler> invocationList) { - this.SourceMods.Remove(handler); - this.CachedInvocationList = invocationList.ToArray(); + this.CachedInvocationList = invocationList?.ToArray() ?? new TEventHandler[0]; + if(!this.CachedInvocationList.Contains(handler)) // don't remove if there's still a reference to the removed handler (e.g. it was added twice and removed once) + this.SourceMods.Remove(handler); } /// <summary>Log an exception from an event handler.</summary> |