diff --git a/engine/breeze/ai/behaviour_tree.c b/engine/breeze/ai/behaviour_tree.c index 80c35d4..b303920 100644 --- a/engine/breeze/ai/behaviour_tree.c +++ b/engine/breeze/ai/behaviour_tree.c @@ -470,8 +470,13 @@ static inline BzBTExecReturn bzBTExecuteComposite(const BzBTNode *node, f32 dt, bzBTClearNodeState(pChild, state, statePool); pChild = pChild->next; } + // For finished parallel composites clean up all children + if (finished && isParallel) { + execStateClear(&execReturn.state, statePool); + } if (finished) { + // Finished composites mustn't have state BZ_ASSERT(execReturn.state.first == NULL); if (nodeState) releaseNodeState(nodeState, statePool); return execReturn; @@ -501,12 +506,11 @@ static inline BzBTExecReturn bzBTExecuteDecorator(const BzBTNode *node, f32 dt, case BZ_BT_DECOR_DELAY: nodeState = ensureValidNodeState(node, nodeState, statePool); nodeState->as.delay.elapsed += dt; - execStatePushBack(&execReturn.state, nodeState); if (nodeState->as.delay.elapsed < node->as.delay.ms) { + execStatePushBack(&execReturn.state, nodeState); execReturn.status = BZ_BT_RUNNING; return execReturn; } - BZ_ASSERT(nodeState == execStatePopFront(&execReturn.state)); releaseNodeState(nodeState, statePool); break; default: diff --git a/engine/tests/btree_test.c b/engine/tests/btree_test.c index e5a7b9f..73d6ff9 100644 --- a/engine/tests/btree_test.c +++ b/engine/tests/btree_test.c @@ -27,9 +27,10 @@ bool init(int *game) { // print "Hello, world!" printBT = bzBTMakeRoot(nodePool); BzBTNode *pseq = bzBTCompPSelector(nodePool, printBT); - bzBTDecorDelay(nodePool, pseq, 2.0f); + BzBTNode *node = bzBTDecorFail(nodePool, pseq); + bzBTDecorDelay(nodePool, node, 2.0f); - BzBTNode *node = bzBTDecorRepeat(nodePool, pseq, 5); + node = bzBTDecorRepeat(nodePool, pseq, 5); BzBTNode *seq = bzBTCompSequence(nodePool, node);