From a8a34f7f96a02d668c136415b29c2d622a2546e5 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 24 Feb 2018 20:24:42 -0500 Subject: [PATCH 1/2] fix event error in rare cases --- docs/release-notes.md | 4 ++++ 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 invocationList) { this.SourceMods[handler] = this.ModRegistry.GetFromStack(); - this.CachedInvocationList = invocationList.ToArray(); + this.CachedInvocationList = invocationList?.ToArray() ?? new TEventHandler[0]; } /// Remove tracking for an event handler. @@ -63,8 +63,9 @@ namespace StardewModdingAPI.Framework.Events /// The updated event invocation list. protected void RemoveTracking(TEventHandler handler, IEnumerable 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); } /// Log an exception from an event handler. From f7d0cf40f651b4bf18dbb4fb6669caf1affa5e1e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 24 Feb 2018 20:27:08 -0500 Subject: [PATCH 2/2] update for 2.5.1 release --- build/GlobalAssemblyInfo.cs | 4 ++-- src/SMAPI.Mods.ConsoleCommands/manifest.json | 2 +- src/SMAPI/Constants.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/GlobalAssemblyInfo.cs b/build/GlobalAssemblyInfo.cs index 93e45e30..83bf7d82 100644 --- a/build/GlobalAssemblyInfo.cs +++ b/build/GlobalAssemblyInfo.cs @@ -1,5 +1,5 @@ using System.Reflection; [assembly: AssemblyProduct("SMAPI")] -[assembly: AssemblyVersion("2.5.0")] -[assembly: AssemblyFileVersion("2.5.0")] +[assembly: AssemblyVersion("2.5.1")] +[assembly: AssemblyFileVersion("2.5.1")] diff --git a/src/SMAPI.Mods.ConsoleCommands/manifest.json b/src/SMAPI.Mods.ConsoleCommands/manifest.json index b852f686..645f4315 100644 --- a/src/SMAPI.Mods.ConsoleCommands/manifest.json +++ b/src/SMAPI.Mods.ConsoleCommands/manifest.json @@ -1,7 +1,7 @@ { "Name": "Console Commands", "Author": "SMAPI", - "Version": "2.5.0", + "Version": "2.5.1", "Description": "Adds SMAPI console commands that let you manipulate the game.", "UniqueID": "SMAPI.ConsoleCommands", "EntryDll": "ConsoleCommands.dll" diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 8fe2b55b..3e57ded9 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -37,7 +37,7 @@ namespace StardewModdingAPI ** Public ****/ /// SMAPI's current semantic version. - public static ISemanticVersion ApiVersion { get; } = new SemanticVersion("2.5.0"); + public static ISemanticVersion ApiVersion { get; } = new SemanticVersion("2.5.1"); /// The minimum supported version of Stardew Valley. public static ISemanticVersion MinimumGameVersion { get; } = new SemanticVersion("1.2.30");