From 503f04af1032d3bb5e726c1d912aad2ee5791de2 Mon Sep 17 00:00:00 2001 From: Carson Kompon Date: Sun, 30 Nov 2025 13:39:50 -0500 Subject: [PATCH] Ensure Playout Builder preserves entire state before creating a new context --- .../SequentialPlayoutBuilder.cs | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/ErsatzTV.Core/Scheduling/YamlScheduling/SequentialPlayoutBuilder.cs b/ErsatzTV.Core/Scheduling/YamlScheduling/SequentialPlayoutBuilder.cs index d3dea6956..d8da693d6 100644 --- a/ErsatzTV.Core/Scheduling/YamlScheduling/SequentialPlayoutBuilder.cs +++ b/ErsatzTV.Core/Scheduling/YamlScheduling/SequentialPlayoutBuilder.cs @@ -317,7 +317,7 @@ public class SequentialPlayoutBuilder( // Switch to the new schedule currentSchedule = newSchedule; - + // Get the new schedule's instructions List newPlayoutInstructions; if (newSchedule != null) @@ -366,19 +366,49 @@ public class SequentialPlayoutBuilder( newFlattenCount++; } - // Preserve existing items and history, create new context with new definition + // Preserve existing state before creating new context var previousAddedItems = context.AddedItems.ToList(); var previousAddedHistory = context.AddedHistory.ToList(); - + var previousPreRollSequence = context.GetPreRollSequence(); + var previousPostRollSequence = context.GetPostRollSequence(); + var previousMidRollSequence = context.GetMidRollSequence(); + var previousWatermarkIds = context.GetChannelWatermarkIds(); + var previousGraphicsElements = context.GetGraphicsElements(); + context = new YamlPlayoutContext(playout, effectiveDefinition, 1) { CurrentTime = context.CurrentTime, InstructionIndex = 0 // Start from beginning of new schedule }; - - // Restore the items and history + + // Restore all preserved state context.AddedItems.AddRange(previousAddedItems); context.AddedHistory.AddRange(previousAddedHistory); + + foreach (string preRoll in previousPreRollSequence) + { + context.SetPreRollSequence(preRoll); + } + + foreach (string postRoll in previousPostRollSequence) + { + context.SetPostRollSequence(postRoll); + } + + foreach (var midRoll in previousMidRollSequence) + { + context.SetMidRollSequence(midRoll); + } + + foreach (int watermarkId in previousWatermarkIds) + { + context.SetChannelWatermarkId(watermarkId); + } + + foreach (var (graphicsId, variablesJson) in previousGraphicsElements) + { + context.SetGraphicsElement(graphicsId, variablesJson); + } } if (context.InstructionIndex >= effectiveDefinition.Playout.Count)