diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-07-21 13:57:28 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-07-21 13:57:28 -0400 |
commit | 6f9a1f1525331db3c9fc089e98193e082add3329 (patch) | |
tree | de531d4dce331d7ea15f99cb5ba649edd15d52db /src/SMAPI/Framework/Events/ManagedEvent.cs | |
parent | 4b07e1052027947186b6a7d4de489b5dc6a9d4f0 (diff) | |
download | SMAPI-6f9a1f1525331db3c9fc089e98193e082add3329.tar.gz SMAPI-6f9a1f1525331db3c9fc089e98193e082add3329.tar.bz2 SMAPI-6f9a1f1525331db3c9fc089e98193e082add3329.zip |
fix error when a mod adds/remove an event handler while handling the event
Diffstat (limited to 'src/SMAPI/Framework/Events/ManagedEvent.cs')
-rw-r--r-- | src/SMAPI/Framework/Events/ManagedEvent.cs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/SMAPI/Framework/Events/ManagedEvent.cs b/src/SMAPI/Framework/Events/ManagedEvent.cs index 08ac1131..8b25a9b5 100644 --- a/src/SMAPI/Framework/Events/ManagedEvent.cs +++ b/src/SMAPI/Framework/Events/ManagedEvent.cs @@ -106,19 +106,20 @@ namespace StardewModdingAPI.Framework.Events // update cached data // (This is debounced here to avoid repeatedly sorting when handlers are added/removed, // and keeping a separate cached list allows changes during enumeration.) - if (this.CachedHandlers == null) + var handlers = this.CachedHandlers; // iterate local copy in case a mod adds/removes a handler while handling the event + if (handlers == null) { if (this.HasNewHandlers && this.Handlers.Any(p => p.Priority != EventPriority.Normal)) this.Handlers.Sort(); - this.CachedHandlers = this.Handlers.ToArray(); + this.CachedHandlers = handlers = this.Handlers.ToArray(); this.HasNewHandlers = false; } // raise event this.PerformanceMonitor.Track(this.EventName, () => { - foreach (ManagedEventHandler<TEventArgs> handler in this.CachedHandlers) + foreach (ManagedEventHandler<TEventArgs> handler in handlers) { if (match != null && !match(handler.SourceMod)) continue; |