From e209ef566df0f7ebebbc1e0ca7c2c0ed1e0b4092 Mon Sep 17 00:00:00 2001 From: Robert Sanders Date: Thu, 18 Jun 2026 22:14:18 -0400 Subject: [PATCH] fix: harden route execution and normalize source port mapping --- .../Routing/RouteDescriptor.cs | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Routing/RouteDescriptor.cs b/src/PepperDash.Essentials.Core/Routing/RouteDescriptor.cs index e698ae0d..f0e9309e 100644 --- a/src/PepperDash.Essentials.Core/Routing/RouteDescriptor.cs +++ b/src/PepperDash.Essentials.Core/Routing/RouteDescriptor.cs @@ -92,19 +92,48 @@ namespace PepperDash.Essentials.Core { Debug.LogVerbose("ExecuteRoutes: {0}", route.ToString()); + var inputSelector = route.InputPort?.Selector ?? route.InputPort?.Key; + if (route.SwitchingDevice is IRoutingSinkWithSwitching sink) { - sink.ExecuteSwitch(route.InputPort.Selector); + try + { + sink.ExecuteSwitch(inputSelector); + } + catch (Exception) + { + // Some devices expose null/unsupported selectors but can switch by port key. + if (route.InputPort?.Key != null && !Equals(inputSelector, route.InputPort.Key)) + { + sink.ExecuteSwitch(route.InputPort.Key); + } + else + { + throw; + } + } + continue; } if (route.SwitchingDevice is IRouting switchingDevice) { - switchingDevice.ExecuteSwitch(route.InputPort.Selector, route.OutputPort.Selector, SignalType); + // Some sink-style routing devices can produce route descriptors without an explicit output port. + if (route.OutputPort == null) + { + switchingDevice.ExecuteSwitch(inputSelector, null, SignalType); + continue; + } - route.OutputPort.InUseTracker.AddUser(Destination, "destination-" + SignalType); + var outputSelector = route.OutputPort.Selector ?? route.OutputPort.Key; + switchingDevice.ExecuteSwitch(inputSelector, outputSelector, SignalType); - Debug.LogVerbose("Output port {0} routing. Count={1}", route.OutputPort.Key, route.OutputPort.InUseTracker.InUseCountFeedback.UShortValue); + route.OutputPort.InUseTracker?.AddUser(Destination, "destination-" + SignalType); + + if (route.OutputPort.InUseTracker != null) + { + Debug.LogVerbose("Output port {0} routing. Count={1}", route.OutputPort.Key, route.OutputPort.InUseTracker.InUseCountFeedback.UShortValue); + } } } } @@ -125,7 +154,7 @@ namespace PepperDash.Essentials.Core { try { - switchingDevice.ExecuteSwitch(null, route.OutputPort.Selector, SignalType); + switchingDevice.ExecuteSwitch(null, route.OutputPort?.Selector, SignalType); } catch (Exception e) {