From 7ab8bac5063d0967758e915ff82735e342883342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=AB=E7=84=B0=E5=BA=93=E6=8B=89?= <820449643@qq.com> Date: Thu, 26 Feb 2026 10:26:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(scene-script):=20=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E5=AF=B9=E7=BB=84=E4=BB=B6=E6=A0=B8=E5=BF=83=E5=B1=9E=E6=80=A7?= =?UTF-8?q?(node=E7=AD=89)=E7=9A=84=E4=BF=AE=E6=94=B9=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E7=BC=96=E8=BE=91=E5=99=A8=E5=8D=A1=E6=AD=BB=E5=B4=A9?= =?UTF-8?q?=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UPDATE_LOG.md | 9 +++++++++ scene-script.js | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/UPDATE_LOG.md b/UPDATE_LOG.md index c5cf915..3eca84d 100644 --- a/UPDATE_LOG.md +++ b/UPDATE_LOG.md @@ -193,3 +193,12 @@ 1. **直接拦截节点**: 当检测到传入 `cc.Node` 或 `Node` 作为组件类型时直接驳回,并返回富含指导意义的中文提示词(如“请使用 create-node 创建节点”)。 2. **继承链校验**: 提取引擎类定义后,强制要求通过 `cc.js.isChildClassOf` 判断该类必须继承自 `cc.Component`。若不合法则即时截断并提示。 - **价值**: 通过将冰冷的底层异常翻译为“手把手教 AI 怎么重试”的指导性异常,彻底根治了 AI 在操作组件时乱认对象、反复撞墙的通病。 + +--- + +## 防止核心属性被篡改崩溃 (2026-02-26) + +### 1. `manage_components` 核心属性保护 + +- **问题**: AI 助手在使用 `manage_components` 尝试修改 `Label` 位置时,错误地对组件传参 `{ node: { position: ... } }`,导致 Label 的 `this.node` 强引用被覆写为普通对象。引发渲染报错 (`Cannot read property 'a' of undefined`) 和删除卡死 (`this.node._removeComponent is not a function`)。 +- **修复**: 在 `scene-script.js` 的 `applyProperties` 中增加了核心属性黑名单机制。强制拦截对 `node`, `uuid`, `_id` 的直接写入并给出警告。彻底杜绝由于组件的节点引用被破坏所引发的场景崩溃和编辑器卡死问题。 diff --git a/scene-script.js b/scene-script.js index 1f54b86..67e3356 100644 --- a/scene-script.js +++ b/scene-script.js @@ -341,6 +341,15 @@ module.exports = { const compClass = component.constructor; for (const [key, value] of Object.entries(props)) { + // 【防呆设计】拦截对核心只读属性的非法重写 + // 如果直接修改组件的 node 属性,会导致该引用丢失变成普通对象,进而引发编辑器卡死 + if (key === "node" || key === "uuid" || key === "_id") { + Editor.warn( + `[scene-script] 拒绝覆盖组件的只读/核心属性: ${key}。请勿对组件执行此操作,修改位置/激活状态等请操作 Node 节点!`, + ); + continue; + } + // 【核心修复】专门处理各类事件属性 (ClickEvents, ScrollEvents 等) const isEventProp = Array.isArray(value) && (key.toLowerCase().endsWith("events") || key === "clickEvents"); From 813cfa328e732ded06852ce76a7941da51154382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=AB=E7=84=B0=E5=BA=93=E6=8B=89?= <820449643@qq.com> Date: Thu, 26 Feb 2026 11:01:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(main):=20=E4=B8=BA=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=93=8D=E4=BD=9C=E6=B7=BB=E5=8A=A0=20'save'?= =?UTF-8?q?=20=E5=88=AB=E5=90=8D=E5=85=BC=E5=AE=B9=20AI=20=E5=B9=BB?= =?UTF-8?q?=E8=A7=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UPDATE_LOG.md | 5 +++++ main.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/UPDATE_LOG.md b/UPDATE_LOG.md index 3eca84d..5094c75 100644 --- a/UPDATE_LOG.md +++ b/UPDATE_LOG.md @@ -202,3 +202,8 @@ - **问题**: AI 助手在使用 `manage_components` 尝试修改 `Label` 位置时,错误地对组件传参 `{ node: { position: ... } }`,导致 Label 的 `this.node` 强引用被覆写为普通对象。引发渲染报错 (`Cannot read property 'a' of undefined`) 和删除卡死 (`this.node._removeComponent is not a function`)。 - **修复**: 在 `scene-script.js` 的 `applyProperties` 中增加了核心属性黑名单机制。强制拦截对 `node`, `uuid`, `_id` 的直接写入并给出警告。彻底杜绝由于组件的节点引用被破坏所引发的场景崩溃和编辑器卡死问题。 + +### 2. 资源管理层 `save` 动作幻觉别名兼容 + +- **问题**: AI 偶尔会幻觉以为 `prefab_management`/`manage_script`/`manage_material`/`manage_texture`/`manage_shader` 的更新动作为 `save`,而不是标准定义的 `update` 或 `write`,导致抛出“未知的管理操作”报错。 +- **修复**: 在 `main.js` 所有这些管理工具的核心路由表中,为 `update` 和 `write` 操作均显式添加了 `case "save":` 作为后备兼容,极大地增强了不同大模型在不同提示词上下文环境下的操作容错率。 diff --git a/main.js b/main.js index 02aabe8..53032cd 100644 --- a/main.js +++ b/main.js @@ -1292,6 +1292,7 @@ export default class NewScript extends cc.Component { } break; + case "save": // 兼容 AI 幻觉 case "write": // 使用 fs 写入 + refresh,确保覆盖成功 const writeFsPath = Editor.assetdb.urlToFspath(scriptPath); @@ -1548,6 +1549,7 @@ export default class NewScript extends cc.Component { callback(null, `指令已发送: 从节点 ${nodeId} 在目录 ${targetDir} 创建名为 ${prefabName} 的预制体`); break; + case "save": // 兼容 AI 幻觉 case "update": if (!nodeId) { return callback("更新预制体需要节点 ID"); @@ -1723,6 +1725,7 @@ CCProgram fs %{ } break; + case "save": // 兼容 AI 幻觉 case "write": if (!Editor.assetdb.exists(effectPath)) { return callback(`Effect not found: ${effectPath}`); @@ -1803,6 +1806,7 @@ CCProgram fs %{ }); break; + case "save": // 兼容 AI 幻觉 case "update": if (!Editor.assetdb.exists(matPath)) { return callback(`找不到材质: ${matPath}`); @@ -1963,6 +1967,7 @@ CCProgram fs %{ callback(`找不到纹理: ${path}`); } break; + case "save": // 兼容 AI 幻觉 case "update": if (!Editor.assetdb.exists(path)) { return callback(`找不到纹理: ${path}`);