Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Forge.Tests/Statescript/GraphProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,42 @@ public void Stopping_graph_fires_on_graph_completed_once()
value.Should().Be(1);
}

[Fact]
[Trait("Graph", "Lifecycle")]
public void Stopping_graph_resolves_property_inputs_during_deactivation_cascade()
{
var graph = new Graph();
graph.VariableDefinitions.DefineVariable("duration", 100.0);
graph.VariableDefinitions.DefineProperty(
"constant",
new VariantResolver(new Variant128(42), typeof(int)));

TimerNode timer = CreateTimerNode("duration");
var readNode = new ReadPropertyNode<int>();
readNode.BindInput(ReadPropertyNode<int>.ValueInput, "constant");

graph.AddNode(timer);
graph.AddNode(readNode);
graph.AddConnection(new Connection(
graph.EntryNode.OutputPorts[EntryNode.OutputPort],
timer.InputPorts[StateNode<TimerNodeContext>.InputPort]));
graph.AddConnection(new Connection(
timer.OutputPorts[StateNode<TimerNodeContext>.OnDeactivatePort],
readNode.InputPorts[ActionNode.InputPort]));

var processor = new GraphProcessor(graph);
processor.StartGraph();

processor.GraphContext.IsActive.Should().BeTrue();

processor.StopGraph();

readNode.ExecutionCount.Should().Be(1);
readNode.Found.Should().BeTrue(
"property-backed inputs must still resolve during the StopGraph deactivation cascade");
readNode.LastReadValue.Should().Be(42);
}

[Fact]
[Trait("Graph", "Complex")]
public void Complex_graph_with_condition_and_multiple_actions_executes_correctly()
Expand Down
5 changes: 4 additions & 1 deletion Forge/Statescript/GraphProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ public void StopGraph()
return;
}

GraphContext.Processor = null;
// Clear HasStarted first so the disable cascade is re-entrancy safe (e.g. an ExitNode triggering StopGraph, or a
// state node reaching FinalizeGraph) without nulling Processor yet. Keeping Processor set throughout the cascade
// lets action nodes on OnDeactivate paths still resolve property-backed inputs.
GraphContext.HasStarted = false;
Graph.EntryNode.StopGraph(GraphContext);
GraphContext.Processor = null;
GraphContext.ActiveStateNodes.Clear();
GraphContext.InternalNodeActivationStatus.Clear();
GraphContext.RemoveAllNodeContext();
Expand Down
Loading