mirror of
https://github.com/gongxh0901/kunpocc-behaviortree.git
synced 2025-12-26 16:48:56 +00:00
修复行为树关键bug
- 修复BehaviorTree.ts中lastOpenNodes的空指针风险 - 修复Ticker.ts中closeNode栈操作不对称问题 - 修复Agent.ts中subject参数传递错误 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -25,7 +25,7 @@ export class Agent {
|
||||
* 执行
|
||||
*/
|
||||
public tick(): void {
|
||||
this.tree.tick(this, this.blackboard, this.ticker);
|
||||
this.tree.tick(this.ticker.subject, this.blackboard, this.ticker);
|
||||
if (this.blackboard.interrupt) {
|
||||
this.blackboard.interrupt = false;
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ export class BehaviorTree {
|
||||
ticker.openNodes.length = 0;
|
||||
this._root._execute(ticker);
|
||||
// 上次打开的节点
|
||||
let lastOpenNodes = blackboard.get("openNodes", this._id) as BaseNode[];
|
||||
let lastOpenNodes = (blackboard.get("openNodes", this._id) || []) as BaseNode[];
|
||||
// 当前打开的节点
|
||||
let currOpenNodes = ticker.openNodes;
|
||||
let start = 0;
|
||||
|
||||
@@ -44,7 +44,11 @@ export class Ticker {
|
||||
* @param node 节点
|
||||
*/
|
||||
public closeNode(node: BaseNode): void {
|
||||
this.openNodes.pop();
|
||||
// 查找并移除指定节点,而不是简单地pop
|
||||
const index = this.openNodes.lastIndexOf(node);
|
||||
if (index !== -1) {
|
||||
this.openNodes.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user