Skip to content

feat: support source-v2 migration runtime and physics compatibility#3066

Draft
luzhuang wants to merge 15 commits into
dev/2.0from
feat/migrate-2.0
Draft

feat: support source-v2 migration runtime and physics compatibility#3066
luzhuang wants to merge 15 commits into
dev/2.0from
feat/migrate-2.0

Conversation

@luzhuang

@luzhuang luzhuang commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • support canonical glTF scene sub-assets and selected scene roots
  • harden physics stepping, contact-event demand, kinematic synchronization, scaled defaults, and cloned collider state
  • make mesh collider cooking, ownership, and rollback transactional on both false returns and native exceptions

Scope

This PR now contains only the physics and glTF compatibility required by migrated Engine 2.0 projects. Generic runtime constructed values and nested calls were moved to #3067; Editor source-v2 compilation is in galacean/editor#3793. Particle Core collection setters and global Math class registration were removed.

Validation

  • pnpm build
  • pnpm lint (0 errors)
  • focused changed test files: 246 tests passed before the Loader split
  • migrated 下落2048 and 保卫萝卜 built against Engine 2.0.0-alpha.38 with runtime component validation
  • final diff check confirms no duplicate Loader contract or Particle Core serialization API remains

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This PR updates physics synchronization and native resource handling, adds particle collection setters, exposes canonical glTF scene selection, normalizes resource cache lookup, registers engine math classes, preserves transform state during replacement, and expands regression coverage across core, loader, and physics behavior.

Changes

Core state and particle serialization

Layer / File(s) Summary
Entity and script state preservation
.gitignore, packages/core/src/Entity.ts, packages/core/src/Script.ts, tests/src/core/Transform.test.ts
Transform replacement preserves position, rotation, and scale; collision callback changes invalidate physics demand detection; local notes are ignored.
Particle collection replacement
packages/core/src/particle/modules/*, tests/src/core/particle/*
Burst, curve-key, and gradient-key collections can be replaced through serializable setters while preserving sorting, listeners, and channel state.

Physics behavior and native integration

Layer / File(s) Summary
Physics contracts, timing, and event demand
packages/design/src/physics/*, packages/core/src/physics/PhysicsScene.ts, packages/physics-physx/src/PhysXPhysics*
Physics defaults, maximum simulation delta time, and native contact-event buffering are exposed and synchronized.
Collider lifecycle and dynamic synchronization
packages/core/src/physics/*, packages/physics-physx/src/PhysXDynamicCollider.ts, packages/physics-physx/src/PhysXCharacterController.ts, packages/physics-physx/src/shape/PhysXColliderShape.ts
Collider re-entry and cloning use teleport alignment; kinematic sync, CCD transitions, force handling, quaternion normalization, and contact offsets are updated.
Material cloning and mesh ownership
packages/core/src/physics/PhysicsMaterial.ts, packages/core/src/physics/shape/*, packages/physics-physx/src/shape/PhysXMeshColliderShape.ts
Native material values are synchronized during cloning, and mesh cooking, attachment, replacement, cloning, and cleanup report failures transactionally.
Physics regression coverage
tests/src/core/physics/*
Tests cover contact normals, event demand, timing limits, dynamic behavior, cloning, CCD, materials, mesh ownership, and failure recovery.

Loader, resources, and runtime registration

Layer / File(s) Summary
Canonical glTF scene sub-assets
packages/loader/src/gltf/*, packages/loader/src/resource-deserialize/resources/parser/HierarchyParser.ts, tests/src/loader/GLTFLoader.test.ts, tests/src/loader/SceneFormatV2.test.ts
glTF scenes are exposed through scenes[index], selected scene roots are instantiated, and scene-format tests cover the resolution path.
Loader registration, reflection, and cache normalization
packages/core/src/asset/ResourceManager.ts, packages/galacean/src/index.ts, packages/loader/src/resource-deserialize/resources/parser/*, packages/loader/src/schema/CommonSchema.ts, tests/src/core/resource/ResourceManager.test.ts, tests/src/loader/SceneFormatV2.test.ts
Cache lookups use mapped remote URLs, engine math classes are registered with the loader, nested calls and $type constructor arguments are resolved, and the schema documents these values.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related issues

Possibly related PRs

  • galacean/engine#2880 — Updates the same mesh-collider and PhysX mesh-cooking implementation areas.
  • galacean/engine#2930 — Directly relates to dynamic native contact-event enablement based on collision callback consumers.

Suggested labels: enhancement, engine, physics, loader, glTF, particle

Suggested reviewers: guolei1990, zhuxudong

Poem

I’m a rabbit with code in my paws,
Physics now hops without pause.
Bursts sort in line, scenes bloom bright,
Colliders teleport just right.
Math classes join the loader’s tune—
A carrot-sized patch beneath the moon.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the PR’s main goal of adding source-v2 migration runtime support and physics compatibility updates.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/migrate-2.0

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/core/src/particle/modules/ParticleCurve.ts (1)

90-96: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

setKeys leaks callbacks and lacks pre-validation, unlike ParticleGradient.setKeys.

Two issues compared to the ParticleGradient.setKeys pattern:

  1. Callback leak: Old CurveKey objects are cleared from the array without unregistering their _updateDispatch callback. removeKey (line 82) properly calls _unRegisterOnValueChanged, but setKeys does not. If old keys are shared or reused, their value changes will trigger stale dispatches on this curve.

  2. No input length pre-validation: If called with >4 keys, addKey throws on the 5th key — but the old keys are already cleared, leaving the curve in a broken state with data loss. ParticleGradient.setKeys validates length > 4 before clearing.

🔧 Proposed fix: unregister old callbacks and pre-validate length
 setKeys(keys: ReadonlyArray<CurveKey>): void {
+    if (keys.length > 4) {
+      throw new Error("Curve can only have 4 keys");
+    }
+
+    const currentKeys = this._keys;
+    for (let i = 0, n = currentKeys.length; i < n; i++) {
+      currentKeys[i]._unRegisterOnValueChanged(this._updateDispatch);
+    }
     this._keys.length = 0;
     for (let i = 0, n = keys.length; i < n; i++) {
       this.addKey(keys[i]);
     }
     this._typeArrayDirty = true;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core/src/particle/modules/ParticleCurve.ts` around lines 90 - 96,
Update ParticleCurve.setKeys to reject inputs longer than four keys before
mutating the existing collection, preserving the current keys when validation
fails. On valid input, unregister each existing key’s _updateDispatch callback
before clearing the array, then add the replacement keys and mark
_typeArrayDirty as currently done.
🧹 Nitpick comments (2)
packages/galacean/src/index.ts (1)

22-24: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the duplicate math registration loop.

MathObjects is registered once at Lines 18–20 and then immediately registered again at Lines 22–24. Remove the second loop to avoid redundant startup work and potential duplicate-registration side effects.

Proposed cleanup
-for (let key in MathObjects) {
-  Loader.registerClass(key, MathObjects[key]);
-}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/galacean/src/index.ts` around lines 22 - 24, Remove the duplicate
for-in registration loop over MathObjects following the existing registration
block, leaving the initial MathObjects registration through Loader.registerClass
unchanged.
tests/src/loader/GLTFLoader.test.ts (1)

605-617: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Exercise the uncached sub-asset path.

Because the root asset is loaded first, the second request is resolved through the cache and glTFResource.scenes[0]; it does not exercise the changed GLTFParserContext callback for scenes[0]. Query the sub-asset first, or use a fresh manager/fixture, so this test verifies pending sub-asset resolution as well.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/src/loader/GLTFLoader.test.ts` around lines 605 - 617, Update the test
around the “resolves scene sub-assets by the canonical glTF schema key” case so
the queried scenes[0] sub-asset loads before the root GLTF resource, or use a
fresh resource manager/fixture. Ensure the assertion still compares the resolved
scene to glTFResource.scenes[0] while exercising uncached pending sub-asset
resolution through GLTFParserContext.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/src/physics/PhysicsScene.ts`:
- Around line 855-883: Update _hasCollisionEventConsumers to skip null entries
when reading scripts._elements, matching the element guard used by
DisorderedArray.forEach and _dispatchEvents. Check each script before accessing
onCollisionEnter, onCollisionExit, or onCollisionStay, while preserving the
existing consumer cache behavior for valid scripts.

In `@packages/core/src/physics/shape/MeshColliderShape.ts`:
- Around line 26-33: Update the cookingFlags setter and its native mesh-update
path around _updateNativeShapeData so exceptions from
PhysXMeshColliderShape.setMeshData are handled transactionally, not only false
returns. Track whether the native update succeeded, and in a finally block
restore the previous cooking flags plus the prior mesh, buffers, and reference
counts whenever it did not; preserve the successful update path unchanged.

In
`@packages/loader/src/resource-deserialize/resources/parser/HierarchyParser.ts`:
- Around line 293-317: After resolving the resource in the promise within
HierarchyParser’s asset-loading flow, validate glTFSceneSelection.sceneIndex
against the resolved GLTFResource’s scenes collection before calling
instantiateSceneRoot. Reject out-of-range indices with a clear error identifying
the requested scene key and asset reference, while preserving the existing
prefab handling and valid-index instantiation behavior.

In `@packages/physics-physx/src/PhysXPhysics.ts`:
- Around line 60-88: Validate resolvedOptions?.tolerancesScale for positive
finite length and speed in the PhysXPhysics constructor before assigning
_tolerancesScaleOptions or calling _updateScaledDefaults. Reuse the existing
validation behavior from _applyTolerancesScale, and throw immediately for
invalid values so initialization cannot proceed with invalid defaults.

In `@tests/src/core/physics/MeshColliderShape.test.ts`:
- Line 311: Remove the `_isShapeAttached` assertions from the MeshColliderShape
tests, including the checks on clonedShape and the other indicated cases. Keep
the adjacent native-shape count assertions, which already validate attachment
ownership.

In `@tests/src/core/physics/PhysicsScene.test.ts`:
- Around line 99-101: Update getLastContactEventDemandCall to distinguish an
empty calls array from a native call returning false; do not use false as the
missing-call fallback. Make the helper expose or throw on the missing-call case
so disable-demand tests fail when setContactEventEnabled was never invoked,
while preserving false for an actual recorded call.

In `@tests/src/core/Transform.test.ts`:
- Around line 119-122: Update the rotation assertion in the Transform test to
use an approximate comparison with an appropriate tolerance instead of exact
deep inclusion, while leaving the position and scale assertions unchanged.
- Around line 128-130: Update the second rotation assertion in the transform
test to use approximate floating-point comparison for the y value, matching the
tolerance approach used by the earlier rotation assertion, while preserving the
expected rotation of x: 0, y: 90, z: 0.

---

Outside diff comments:
In `@packages/core/src/particle/modules/ParticleCurve.ts`:
- Around line 90-96: Update ParticleCurve.setKeys to reject inputs longer than
four keys before mutating the existing collection, preserving the current keys
when validation fails. On valid input, unregister each existing key’s
_updateDispatch callback before clearing the array, then add the replacement
keys and mark _typeArrayDirty as currently done.

---

Nitpick comments:
In `@packages/galacean/src/index.ts`:
- Around line 22-24: Remove the duplicate for-in registration loop over
MathObjects following the existing registration block, leaving the initial
MathObjects registration through Loader.registerClass unchanged.

In `@tests/src/loader/GLTFLoader.test.ts`:
- Around line 605-617: Update the test around the “resolves scene sub-assets by
the canonical glTF schema key” case so the queried scenes[0] sub-asset loads
before the root GLTF resource, or use a fresh resource manager/fixture. Ensure
the assertion still compares the resolved scene to glTFResource.scenes[0] while
exercising uncached pending sub-asset resolution through GLTFParserContext.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f46c8a75-16be-493c-8c80-88d2aaff1e24

📥 Commits

Reviewing files that changed from the base of the PR and between 75af66f and f018378.

⛔ Files ignored due to path filters (1)
  • packages/shader/src/ShaderLibrary/Skin/Skin.glsl is excluded by !**/*.glsl
📒 Files selected for processing (40)
  • .gitignore
  • packages/core/src/Entity.ts
  • packages/core/src/Script.ts
  • packages/core/src/asset/ResourceManager.ts
  • packages/core/src/particle/modules/EmissionModule.ts
  • packages/core/src/particle/modules/ParticleCurve.ts
  • packages/core/src/particle/modules/ParticleGradient.ts
  • packages/core/src/physics/CharacterController.ts
  • packages/core/src/physics/Collider.ts
  • packages/core/src/physics/Collision.ts
  • packages/core/src/physics/DynamicCollider.ts
  • packages/core/src/physics/PhysicsMaterial.ts
  • packages/core/src/physics/PhysicsScene.ts
  • packages/core/src/physics/index.ts
  • packages/core/src/physics/shape/ColliderShape.ts
  • packages/core/src/physics/shape/MeshColliderShape.ts
  • packages/design/src/physics/IPhysics.ts
  • packages/design/src/physics/IPhysicsScene.ts
  • packages/galacean/src/index.ts
  • packages/loader/src/gltf/GLTFResource.ts
  • packages/loader/src/gltf/parser/GLTFParserContext.ts
  • packages/loader/src/resource-deserialize/resources/parser/HierarchyParser.ts
  • packages/physics-physx/src/PhysXCharacterController.ts
  • packages/physics-physx/src/PhysXDynamicCollider.ts
  • packages/physics-physx/src/PhysXPhysics.ts
  • packages/physics-physx/src/PhysXPhysicsScene.ts
  • packages/physics-physx/src/index.ts
  • packages/physics-physx/src/shape/PhysXColliderShape.ts
  • packages/physics-physx/src/shape/PhysXMeshColliderShape.ts
  • tests/src/core/Transform.test.ts
  • tests/src/core/particle/Burst.test.ts
  • tests/src/core/particle/ParticleSerialization.test.ts
  • tests/src/core/physics/Collision.test.ts
  • tests/src/core/physics/DynamicCollider.test.ts
  • tests/src/core/physics/MeshColliderShape.test.ts
  • tests/src/core/physics/PhysicsMaterial.test.ts
  • tests/src/core/physics/PhysicsScene.test.ts
  • tests/src/core/resource/ResourceManager.test.ts
  • tests/src/loader/GLTFLoader.test.ts
  • tests/src/loader/SceneFormatV2.test.ts

Comment thread packages/core/src/physics/PhysicsScene.ts
Comment thread packages/core/src/physics/shape/MeshColliderShape.ts
Comment thread packages/physics-physx/src/PhysXPhysics.ts Outdated
Comment thread tests/src/core/physics/MeshColliderShape.test.ts
Comment thread tests/src/core/physics/PhysicsScene.test.ts Outdated
Comment thread tests/src/core/Transform.test.ts
Comment thread tests/src/core/Transform.test.ts
GuoLei1990

This comment was marked as outdated.

@luzhuang luzhuang marked this pull request as draft July 13, 2026 06:38
@luzhuang luzhuang changed the title fix: align source-v2 and physics migration semantics feat: support source-v2 migration runtime and physics compatibility Jul 14, 2026
@luzhuang luzhuang marked this pull request as ready for review July 14, 2026 09:10
@luzhuang

Copy link
Copy Markdown
Contributor Author

Review feedback is addressed in 4252f17ab:

  • changed the PR to feat: and removed the unrelated baked-skinning shader path
  • made mesh recooking rollback transactional for both false returns and thrown native errors
  • centralized glTF scene bounds validation in GLTFResource.instantiateSceneRoot, so every caller gets the same descriptive failure
  • moved PhysX tolerance validation to construction time
  • removed duplicate Math registration and fixed the ReflectionParser CI type error
  • made particle collection replacement atomic and detached stale callbacks
  • fixed the glTF uncached-path and Transform precision tests
  • made the contact-demand test distinguish a missing native call from an actual false call

Two suggestions were intentionally not applied: _hasCollisionEventConsumers runs after script iteration when the DisorderedArray has no deferred null slots, so an extra null guard would protect an unreachable state; _isShapeAttached is an inherited ColliderShape field used by production attach/detach ownership, so those assertions remain valid.

Validated with pnpm build, pnpm lint (0 errors), and all 11 changed test files (246/246 passed).

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.77049% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.72%. Comparing base (b7bf6f7) to head (2f0e8ef).

Files with missing lines Patch % Lines
...ce-deserialize/resources/parser/HierarchyParser.ts 70.73% 12 Missing ⚠️
packages/core/src/physics/PhysicsMaterial.ts 60.86% 9 Missing ⚠️
.../physics-physx/src/shape/PhysXMeshColliderShape.ts 83.33% 8 Missing ⚠️
packages/core/src/physics/DynamicCollider.ts 93.75% 4 Missing ⚠️
packages/physics-physx/src/PhysXDynamicCollider.ts 96.25% 3 Missing ⚠️
packages/core/src/physics/shape/ColliderShape.ts 87.50% 1 Missing ⚠️
packages/loader/src/gltf/GLTFResource.ts 94.73% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           dev/2.0    #3066      +/-   ##
===========================================
+ Coverage    79.61%   79.72%   +0.10%     
===========================================
  Files          904      904              
  Lines       101208   101735     +527     
  Branches     11404    11518     +114     
===========================================
+ Hits         80579    81106     +527     
- Misses       20445    20448       +3     
+ Partials       184      181       -3     
Flag Coverage Δ
unittests 79.72% <93.77%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@GuoLei1990 GuoLei1990 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

总结

第二轮审查(tip 4252f17ab「fix: resolve migration runtime review findings」)。该 commit 是精准的 review-response,逐条闭环了首轮的全部阻塞项,且每个 correctness 修复都配了反向证伪测试。CI 全绿(build ×3 / codecov 真 vitest 246/246 / e2e 4/4 / lint)。首轮的 request-changes 门控解除。

已闭环问题清单

  • [P1] fix: 前缀 + 多正交域混装 — 已修复:标题改为 feat:,且移除了整套 RENDERER_USE_BAKED_SKINNING baked-skinning shader 路径Skin.glsl 回归单一 getJointMatrix),把无关的蒙皮新特性从物理迁移 PR 中剥离。
  • [P2] packages/galacean/src/index.ts MathObjects 重复注册 — 已修复:删除第二个 for...in 循环。
  • [P2] 越界 scene index 崩溃 — 已修复:GLTFResource.instantiateSceneRoot 增加 Number.isSafeInteger + <0 + >=length 校验抛 RangeError(含 url + scene 数),并对 _defaultSceneRoot 为空补 Error。收口在单一入口,所有 caller(含 HierarchyParser)统一获得清晰报错。配 GLTFLoader.test.ts 反向测试断言越界抛 out of range
  • [P1] MeshColliderShape 事务性回滚(throw 路径) — 已修复:cookingFlagsmesh 两个 setter 均改 try { updated = _updateNativeShapeData() } finally { if(!updated) revert }false 返回与 native throw 两条路径都回滚。测试 rolls back cached state when native recooking throws 用 spy 抛异常,断言 cookingFlags / mesh / refCount(originalMesh=1 replacementMesh=0)三者全回滚 — revert 修复即红。
  • [P3→已修] PhysXPhysics tolerances 校验 — 校验提前到构造期(_validateTolerancesScale),非法 length/speed 在 new PhysXPhysics(...) 即抛,报错点更早。配 DynamicCollider.test.ts rejects invalid tolerancesScale before initialization
  • [Correction] PhysicsScene null guard — 作者说明「_syncContactEventDemand 在 script 迭代后执行、DisorderedArray 无 deferred null 空洞」,与我首轮结论一致,确认不可达 — 已关闭,不再提。
  • CI type error(ReflectionParser $argsconstructorArgs = $args ?? [] 后统一 Array.isArray 校验,与旧 undefined→[] 语义等价。
  • 粒子集合替换原子性ParticleCurve.setKeys / ParticleGradient.setKeys[...keys] 快照输入再清空,消除「传入自身内部数组 → clear 把输入也清掉」的别名 bug;旧 key 先 _unRegisterOnValueChanged / _onValueChanged=null 解绑 stale callback,新 key 重新注册。配 ParticleSerialization.test.ts 断言 stale key 变更不再触发 dispatch(original.value=4 → changes===0)+ setKeys(自身 keys) 幂等 + 超 4 key 抛错后原状保留。
  • Transform 精度测试deep.include 精确等值改 approximately(…,1e-6),消除浮点抖动 flaky。
  • contact-demand 测试getLastContactEventDemandCall 返回 undefined 而非强制 false,区分「native 调用从未发生」与「真的传了 false」;并从共享 activeScene 改用独立 new Scene,测试隔离更干净。

额外核对

  • _onPhysicsUpdate 每帧重试机制整体移除Collider._onUpdate 的 per-shape loop + ColliderShape 基类 no-op + MeshColliderShape override)— 方向正确。cooking 失败时同一输入每帧重试不会有不同结果,这是纯物理 update 热路径上的死重试,删除是净收益而非回归;与该机制在 #3042 差点被判 P1 的判断一致。
  • _isShapeAttached 确为 ColliderShape.ts:20 的继承字段,供 attach/detach 归属使用,作者保留断言的说明成立。

结论

approve:首轮全部阻塞项已闭环,修复落点正确(事务性回滚在 setter 层、bounds 校验收口在单一入口、别名快照在 setKeys 内部),correctness 类均配反向证伪测试,CI 全绿。无新问题。

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/physics-physx/src/shape/PhysXMeshColliderShape.ts (1)

103-106: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Prevent memory leak by deleting _pxGeometry during destruction.

this._pxGeometry is created dynamically (e.g., via createConvexMeshGeometry) and manually deleted during swaps in setMeshData and _updateGeometry. However, it is not being deleted when the shape is destroyed, which can lead to a memory leak in the Emscripten heap.

🛠️ Proposed fix to clean up geometry
   override destroy(): void {
     this._pxMesh?.release();
+    this._pxGeometry?.delete();
     super.destroy();
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/physics-physx/src/shape/PhysXMeshColliderShape.ts` around lines 103
- 106, Update the destroy() method to delete the dynamically allocated
_pxGeometry before completing destruction, while preserving the existing _pxMesh
release and super.destroy() calls. Ensure cleanup is safe when _pxGeometry is
absent and matches the ownership handling used by setMeshData and
_updateGeometry.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/physics-physx/src/shape/PhysXMeshColliderShape.ts`:
- Around line 103-106: Update the destroy() method to delete the dynamically
allocated _pxGeometry before completing destruction, while preserving the
existing _pxMesh release and super.destroy() calls. Ensure cleanup is safe when
_pxGeometry is absent and matches the ownership handling used by setMeshData and
_updateGeometry.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 18fa3b39-05ff-4026-97fd-e67d0eea3b82

📥 Commits

Reviewing files that changed from the base of the PR and between f018378 and 4252f17.

📒 Files selected for processing (42)
  • .gitignore
  • packages/core/src/Entity.ts
  • packages/core/src/Script.ts
  • packages/core/src/asset/ResourceManager.ts
  • packages/core/src/particle/modules/EmissionModule.ts
  • packages/core/src/particle/modules/ParticleCurve.ts
  • packages/core/src/particle/modules/ParticleGradient.ts
  • packages/core/src/physics/CharacterController.ts
  • packages/core/src/physics/Collider.ts
  • packages/core/src/physics/Collision.ts
  • packages/core/src/physics/DynamicCollider.ts
  • packages/core/src/physics/PhysicsMaterial.ts
  • packages/core/src/physics/PhysicsScene.ts
  • packages/core/src/physics/index.ts
  • packages/core/src/physics/shape/ColliderShape.ts
  • packages/core/src/physics/shape/MeshColliderShape.ts
  • packages/design/src/physics/IPhysics.ts
  • packages/design/src/physics/IPhysicsScene.ts
  • packages/galacean/src/index.ts
  • packages/loader/src/gltf/GLTFResource.ts
  • packages/loader/src/gltf/parser/GLTFParserContext.ts
  • packages/loader/src/resource-deserialize/resources/parser/HierarchyParser.ts
  • packages/loader/src/resource-deserialize/resources/parser/ReflectionParser.ts
  • packages/loader/src/schema/CommonSchema.ts
  • packages/physics-physx/src/PhysXCharacterController.ts
  • packages/physics-physx/src/PhysXDynamicCollider.ts
  • packages/physics-physx/src/PhysXPhysics.ts
  • packages/physics-physx/src/PhysXPhysicsScene.ts
  • packages/physics-physx/src/index.ts
  • packages/physics-physx/src/shape/PhysXColliderShape.ts
  • packages/physics-physx/src/shape/PhysXMeshColliderShape.ts
  • tests/src/core/Transform.test.ts
  • tests/src/core/particle/Burst.test.ts
  • tests/src/core/particle/ParticleSerialization.test.ts
  • tests/src/core/physics/Collision.test.ts
  • tests/src/core/physics/DynamicCollider.test.ts
  • tests/src/core/physics/MeshColliderShape.test.ts
  • tests/src/core/physics/PhysicsMaterial.test.ts
  • tests/src/core/physics/PhysicsScene.test.ts
  • tests/src/core/resource/ResourceManager.test.ts
  • tests/src/loader/GLTFLoader.test.ts
  • tests/src/loader/SceneFormatV2.test.ts
🚧 Files skipped from review as they are similar to previous changes (33)
  • packages/design/src/physics/IPhysics.ts
  • packages/physics-physx/src/index.ts
  • packages/core/src/physics/index.ts
  • tests/src/core/particle/Burst.test.ts
  • tests/src/core/resource/ResourceManager.test.ts
  • packages/core/src/asset/ResourceManager.ts
  • packages/physics-physx/src/PhysXPhysicsScene.ts
  • packages/core/src/Script.ts
  • tests/src/core/particle/ParticleSerialization.test.ts
  • packages/core/src/Entity.ts
  • packages/physics-physx/src/PhysXCharacterController.ts
  • packages/core/src/particle/modules/EmissionModule.ts
  • packages/core/src/physics/Collision.ts
  • packages/loader/src/resource-deserialize/resources/parser/HierarchyParser.ts
  • packages/physics-physx/src/shape/PhysXColliderShape.ts
  • packages/core/src/particle/modules/ParticleCurve.ts
  • packages/loader/src/gltf/parser/GLTFParserContext.ts
  • tests/src/core/physics/MeshColliderShape.test.ts
  • tests/src/core/physics/Collision.test.ts
  • tests/src/core/Transform.test.ts
  • packages/core/src/physics/PhysicsMaterial.ts
  • .gitignore
  • tests/src/core/physics/PhysicsMaterial.test.ts
  • packages/core/src/physics/PhysicsScene.ts
  • packages/core/src/physics/Collider.ts
  • tests/src/core/physics/DynamicCollider.test.ts
  • packages/core/src/physics/CharacterController.ts
  • packages/core/src/particle/modules/ParticleGradient.ts
  • tests/src/core/physics/PhysicsScene.test.ts
  • packages/physics-physx/src/PhysXPhysics.ts
  • packages/core/src/physics/shape/MeshColliderShape.ts
  • packages/physics-physx/src/PhysXDynamicCollider.ts
  • packages/core/src/physics/DynamicCollider.ts

@luzhuang luzhuang marked this pull request as draft July 14, 2026 10:01
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.

2 participants