From 5f77a310c55f6dac19a5c8ca386a091ba2ed2e51 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Thu, 13 Apr 2023 04:14:19 +1000 Subject: [PATCH] Remove `ServiceInjector.ClearServices` This call in `ToolManager.Restart` was to set `[{Optional.Required}Service]` props to `null`, but the tool form would get `Close`d immediately afterwards, so it never gets the chance to hit the `null` path if one exists. However, some tools are written as though they keep the stale value, for example attempting to call a cleanup function on it in their `Closed` event handler. These will now work as intended. `[OptionalService]`s that can't be satisfied are set to `null` by `ServiceInjector.UpdateServices`, so clearing those isn't necessary, and `ClearServices` has no other usages. --- src/BizHawk.Client.EmuHawk/tools/ToolManager.cs | 1 - src/BizHawk.Emulation.Common/ServiceInjector.cs | 16 ---------------- 2 files changed, 17 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs b/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs index 9064166d03..1408b8d805 100644 --- a/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs +++ b/src/BizHawk.Client.EmuHawk/tools/ToolManager.cs @@ -598,7 +598,6 @@ namespace BizHawk.Client.EmuHawk else { unavailable.Add(tool); - ServiceInjector.ClearServices(tool); // the services of the old emulator core are no longer valid on the tool if (tool is IExternalToolForm) ApiInjector.ClearApis(tool); } } diff --git a/src/BizHawk.Emulation.Common/ServiceInjector.cs b/src/BizHawk.Emulation.Common/ServiceInjector.cs index 781945c90b..1b9fe3a6c7 100644 --- a/src/BizHawk.Emulation.Common/ServiceInjector.cs +++ b/src/BizHawk.Emulation.Common/ServiceInjector.cs @@ -10,22 +10,6 @@ namespace BizHawk.Emulation.Common /// public static class ServiceInjector { - /// - /// clears all services from a target - /// - public static void ClearServices(object target) - { - Type targetType = target.GetType(); - object?[] tmp = { null }; - - foreach (var propInfo in - targetType.GetPropertiesWithAttrib(typeof(RequiredServiceAttribute)) - .Concat(targetType.GetPropertiesWithAttrib(typeof(OptionalServiceAttribute)))) - { - propInfo.GetSetMethod(true).Invoke(target, tmp); - } - } - /// /// Feeds the target its required services. ///