修复行为树关键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:
gongxh
2025-07-15 10:38:59 +08:00
parent 8015f3e7ea
commit 0d79db2c58
3 changed files with 7 additions and 3 deletions

View File

@@ -25,7 +25,7 @@ export class Agent {
* 执行 * 执行
*/ */
public tick(): void { 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) { if (this.blackboard.interrupt) {
this.blackboard.interrupt = false; this.blackboard.interrupt = false;

View File

@@ -32,7 +32,7 @@ export class BehaviorTree {
ticker.openNodes.length = 0; ticker.openNodes.length = 0;
this._root._execute(ticker); 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 currOpenNodes = ticker.openNodes;
let start = 0; let start = 0;

View File

@@ -44,7 +44,11 @@ export class Ticker {
* @param node 节点 * @param node 节点
*/ */
public closeNode(node: BaseNode): void { public closeNode(node: BaseNode): void {
this.openNodes.pop(); // 查找并移除指定节点而不是简单地pop
const index = this.openNodes.lastIndexOf(node);
if (index !== -1) {
this.openNodes.splice(index, 1);
}
} }
/** /**