Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parallel task join orchestrator hard-resets its children. #134

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

metaphore
Copy link

@metaphore metaphore commented Feb 2, 2024

The Parallel task's Join orchestrator calls reset() on its children when completed. That renders them unusable for any further use within the tree. Looks like it's a simple mistake of calling reset() (pool-related hard reset for task instances) instead of resetTask() (soft "restart" so the task can be run again).

Here's a simple example that demonstrates the bug.

public class BTreeParallelJoinTest extends ApplicationAdapter {

    private BehaviorTree bTree;

    @Override
    public void create() {
        super.create();

        bTree = new BehaviorTree(
                new Repeat(ConstantIntegerDistribution.NEGATIVE_ONE, // Repeat forever.
                        new Parallel(Parallel.Orchestrator.Join,
                                new AlwaysFail( // Any decorator will do here.
                                        new Success()
                                )
                        )
                )
        );
    }

    @Override
    public void render() {
        super.render();
        bTree.step();
    }
}

The Repeat task crashes on the second iteration at the AlwaysFail decorator as its child was nullified by the reset() call:

Exception in thread "main" java.lang.NullPointerException: Cannot read field "status" because "this.child" is null
	at com.badlogic.gdx.ai.btree.Decorator.run(Decorator.java:65)
	at com.badlogic.gdx.ai.btree.branch.Parallel$Orchestrator$2.execute(Parallel.java:215)
	at com.badlogic.gdx.ai.btree.branch.Parallel.run(Parallel.java:123)
	at com.badlogic.gdx.ai.btree.LoopDecorator.run(LoopDecorator.java:56)
	at com.badlogic.gdx.ai.btree.BehaviorTree.step(BehaviorTree.java:124)
	...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant