From 0e16dff90c89a7b0b0c3f82bf0c81c29ffeb535b Mon Sep 17 00:00:00 2001 From: Nick Genovese Date: Thu, 24 Oct 2024 20:52:24 -0400 Subject: [PATCH] fix: checks the routing output port for null --- .../Routing/RouteDescriptor.cs | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Routing/RouteDescriptor.cs b/src/PepperDash.Essentials.Core/Routing/RouteDescriptor.cs index fa486c07..ee8b69ac 100644 --- a/src/PepperDash.Essentials.Core/Routing/RouteDescriptor.cs +++ b/src/PepperDash.Essentials.Core/Routing/RouteDescriptor.cs @@ -68,19 +68,29 @@ namespace PepperDash.Essentials.Core /// public void ReleaseRoutes() { - foreach (var route in Routes.Where(r => r.SwitchingDevice is IRouting)) - { - if (route.SwitchingDevice is IRouting switchingDevice) - { + foreach (var route in Routes.Where(r => r.SwitchingDevice is IRouting)) + { + if (route.SwitchingDevice is IRouting switchingDevice) + { + if (route.OutputPort == null) + { + continue; + } + switchingDevice.ExecuteSwitch(null, route.OutputPort.Selector, SignalType); - // Pull the route from the port. Whatever is watching the output's in use tracker is - // responsible for responding appropriately. - route.OutputPort.InUseTracker.RemoveUser(Destination, "destination-" + SignalType); - Debug.LogMessage(LogEventLevel.Verbose, "Port {0} releasing. Count={1}",null, route.OutputPort.Key, route.OutputPort.InUseTracker.InUseCountFeedback.UShortValue); - } - } - } + if (route.OutputPort.InUseTracker != null) + { + route.OutputPort.InUseTracker.RemoveUser(Destination, "destination-" + SignalType); + Debug.LogMessage(LogEventLevel.Verbose, "Port {0} releasing. Count={1}", null, route.OutputPort.Key, route.OutputPort.InUseTracker.InUseCountFeedback.UShortValue); + } + else + { + Debug.LogMessage(LogEventLevel.Error, "InUseTracker is null for OutputPort {0}", null, route.OutputPort.Key); + } + } + } + } public override string ToString() {