Skip to content

Commit 891ca53

Browse files
author
Joanna May
authored
Merge pull request #145 from xodial/xodial/fix-infinite-loop
Fix an infinite loop caused when creating input in OnStart
2 parents 62e3477 + 7c6ecd6 commit 891ca53

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Chickensoft.LogicBlocks.Tests/test/src/LogicBlockTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,27 @@ public void ImplicitStartCallsOnStart() {
373373
onStartCalled.ShouldBeTrue();
374374
}
375375

376+
[Fact]
377+
public void OnStartDoesNotCauseInfiniteLoopWithInput() {
378+
var onStartCalled = false;
379+
var looped = false;
380+
var logic = new FakeLogicBlock();
381+
logic.OnStartCalled += () => {
382+
if (onStartCalled) {
383+
looped = true;
384+
return;
385+
}
386+
387+
onStartCalled = true;
388+
logic.Input(new FakeLogicBlock.Input.InputOne(2, 3));
389+
};
390+
391+
logic.Start();
392+
393+
onStartCalled.ShouldBeTrue();
394+
looped.ShouldBeFalse();
395+
}
396+
376397
[Fact]
377398
public void StopExitsState() {
378399
var exitCalled = false;

Chickensoft.LogicBlocks/src/LogicBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,10 @@ internal TState ProcessInputs<TInputType>(
400400

401401
if (_value is null) {
402402
// No state yet. Let's get the first state going!
403-
OnStart();
404403
Blackboard.InstantiateAnyMissingSavedData();
405404
ChangeState(RestoredState as TState ?? GetInitialState().State);
406405
RestoredState = null;
406+
OnStart();
407407
}
408408

409409
// We can always process the first input directly.

0 commit comments

Comments
 (0)