summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Events
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-08-02 16:38:51 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-08-02 16:38:51 -0400
commit8da88b8fe5b41739c5cd0df3280b9770fc7f10a4 (patch)
treeaed3679d01ee546726851982862daac2bad38b41 /src/SMAPI/Framework/Events
parentba0dff819f2e65b16a0c7bc7a9233fdb101994d0 (diff)
parentb96bcb21894257f06716e6a51102f74d2aba5178 (diff)
downloadSMAPI-8da88b8fe5b41739c5cd0df3280b9770fc7f10a4.tar.gz
SMAPI-8da88b8fe5b41739c5cd0df3280b9770fc7f10a4.tar.bz2
SMAPI-8da88b8fe5b41739c5cd0df3280b9770fc7f10a4.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/Events')
-rw-r--r--src/SMAPI/Framework/Events/ManagedEvent.cs7
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;