diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-02-24 20:24:42 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-02-24 20:24:42 -0500 |
commit | a8a34f7f96a02d668c136415b29c2d622a2546e5 (patch) | |
tree | a4b301b14ad7c843ccd89bce0d2725307ea9e4f5 /src/SMAPI | |
parent | 414cf5c197b5b59776d3dda914eb15710efb0868 (diff) | |
download | SMAPI-a8a34f7f96a02d668c136415b29c2d622a2546e5.tar.gz SMAPI-a8a34f7f96a02d668c136415b29c2d622a2546e5.tar.bz2 SMAPI-a8a34f7f96a02d668c136415b29c2d622a2546e5.zip |
fix event error in rare cases
Diffstat (limited to 'src/SMAPI')
-rw-r--r-- | src/SMAPI/Framework/Events/ManagedEventBase.cs | 7 |
1 files changed, 4 insertions, 3 deletions
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> |