Skip to content

fix: ._engine has been deleted#346

Merged
cptbtptpbcptdtptp merged 2 commits intogalacean:dev/2.0from
cptbtptpbcptdtptp:fix/engineMember
Mar 9, 2026
Merged

fix: ._engine has been deleted#346
cptbtptpbcptdtptp merged 2 commits intogalacean:dev/2.0from
cptbtptpbcptdtptp:fix/engineMember

Conversation

@cptbtptpbcptdtptp
Copy link
Collaborator

@cptbtptpbcptdtptp cptbtptpbcptdtptp commented Mar 9, 2026

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Other information:

Summary by CodeRabbit

  • Refactor
    • Standardized internal engine reference usage across multiple materials, icon, XR tracker, and gizmo modules; no public API changes.
  • Style
    • Minor formatting and whitespace adjustments in stats and monitor modules; no behavioral changes.

@coderabbitai
Copy link

coderabbitai bot commented Mar 9, 2026

Walkthrough

Replace private _engine field accesses with the public engine accessor in several modules and apply minor formatting changes in stats files; logic and public APIs remain unchanged.

Changes

Cohort / File(s) Summary
Custom Material Clone Methods
packages/custom-material/src/bake-pbr/BakePBRMaterial.ts, packages/custom-material/src/plain-color/PlainColorMaterial.ts
Replaced this._engine with this.engine when constructing cloned material instances inside clone() implementations.
Gizmo Icon & Material
packages/gizmo/src/icon/Icon.ts, packages/gizmo/src/icon/IconMaterial.ts
Switched constructor/clone instantiation to use the public this.engine accessor instead of this._engine.
XR Tracked Object Manager
packages/xr/src/trackable/XRTrackedObjectManager.ts
Replaced this._engine.xrManager with this.engine.xrManager in XR session handling and tracked component creation.
Stats formatting
packages/stats/src/Core.ts, packages/stats/src/Monitor.ts
Whitespace and formatting-only edits: removed a blank line in Core.ts; reformatted items array literals in Monitor.ts without behavioral changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰
I hopped through code both near and far,
Swapped underscored engines for a public star.
Small edits here, tidy lines there,
A cleaner hop, light as air. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective: replacing all references to the deleted ._engine private field with this.engine across multiple files in the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
packages/xr/src/trackable/XRTrackedObjectManager.ts (1)

51-57: Consider covering the XR engine.xrManager path with a focused test.

Both changed sites are runtime-only branches, so a lightweight session/feature stub test would make this _engineengine migration much safer and catch regressions before XR usage does.

Also applies to: 115-116

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/xr/src/trackable/XRTrackedObjectManager.ts` around lines 51 - 57,
Add a focused unit test that stubs a lightweight XR session/feature path to
cover the engine.xrManager usage in XRTrackedObjectManager: specifically
exercise XRTrackedObjectManager._onSessionChanged with
XRSessionState.Initialized (and the similar branch around lines 115-116) by
mocking this.engine to include an xrManager with a getFeature method that
returns a fake feature object, and assert the code path runs (e.g., that
_initXRFeature is invoked for Initializing and that engine.xrManager.getFeature
is called and handled for Initialized). Ensure the test replaces or spies on
XRTrackedObjectManager._initXRFeature and supplies a minimal feature stub so the
runtime-only branches are executed without a real XR runtime.
packages/custom-material/src/plain-color/PlainColorMaterial.ts (1)

37-40: Add a regression test for material cloning through engine.

This accessor swap is repeated in packages/custom-material/src/bake-pbr/BakePBRMaterial.ts:51-54 and packages/gizmo/src/icon/IconMaterial.ts:47-50. A small clone() test that asserts the clone stays bound to the same engine and preserves copied state would protect the exact API-removal scenario this PR is fixing.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/custom-material/src/plain-color/PlainColorMaterial.ts` around lines
37 - 40, Add a regression test that creates a PlainColorMaterial (using
PlainColorMaterial class), sets identifiable state on it (e.g., color/flags),
then clones it via the engine-backed clone path (exercise the same codepath used
by PlainColorMaterial.clone and the similar implementations in
BakePBRMaterial.clone and IconMaterial.clone) and assert that the resulting
clone is bound to the same engine instance and that all copied state matches the
original; ensure the test covers both calling material.clone() and the
engine-based clone invocation so the accessor-swap regression is caught.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/custom-material/src/plain-color/PlainColorMaterial.ts`:
- Around line 37-40: Add a regression test that creates a PlainColorMaterial
(using PlainColorMaterial class), sets identifiable state on it (e.g.,
color/flags), then clones it via the engine-backed clone path (exercise the same
codepath used by PlainColorMaterial.clone and the similar implementations in
BakePBRMaterial.clone and IconMaterial.clone) and assert that the resulting
clone is bound to the same engine instance and that all copied state matches the
original; ensure the test covers both calling material.clone() and the
engine-based clone invocation so the accessor-swap regression is caught.

In `@packages/xr/src/trackable/XRTrackedObjectManager.ts`:
- Around line 51-57: Add a focused unit test that stubs a lightweight XR
session/feature path to cover the engine.xrManager usage in
XRTrackedObjectManager: specifically exercise
XRTrackedObjectManager._onSessionChanged with XRSessionState.Initialized (and
the similar branch around lines 115-116) by mocking this.engine to include an
xrManager with a getFeature method that returns a fake feature object, and
assert the code path runs (e.g., that _initXRFeature is invoked for Initializing
and that engine.xrManager.getFeature is called and handled for Initialized).
Ensure the test replaces or spies on XRTrackedObjectManager._initXRFeature and
supplies a minimal feature stub so the runtime-only branches are executed
without a real XR runtime.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c79d3a3c-056e-47d7-9c01-49cdfd735b20

📥 Commits

Reviewing files that changed from the base of the PR and between 96c66fb and 762e826.

📒 Files selected for processing (5)
  • packages/custom-material/src/bake-pbr/BakePBRMaterial.ts
  • packages/custom-material/src/plain-color/PlainColorMaterial.ts
  • packages/gizmo/src/icon/Icon.ts
  • packages/gizmo/src/icon/IconMaterial.ts
  • packages/xr/src/trackable/XRTrackedObjectManager.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/stats/src/Monitor.ts (1)

68-78: Formatting improvement looks good.

The multi-line array formatting improves readability.

Minor observation: the empty array assignment on line 68 is immediately overwritten and could be removed, simplifying the initialization to a single assignment.

,

♻️ Optional: Remove redundant empty array assignment
-    this.items = [];
-    this.items = [
+    this.items = [
       "fps",
       "memory",
       "totalGraphicsMemory",
       "textureMemory",
       "bufferMemory",
       "drawCall",
       "triangles",
       "webglContext"
     ];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/stats/src/Monitor.ts` around lines 68 - 78, Remove the redundant
immediate overwrite of this.items by deleting the initial this.items = []; so
the property is initialized once with the multi-line array; update the
constructor or the class initializer in Monitor (look for the this.items
assignment in Monitor.ts) to only contain the single multi-line this.items = [
"fps", "memory", "totalGraphicsMemory", "textureMemory", "bufferMemory",
"drawCall", "triangles", "webglContext" ] assignment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/stats/src/Monitor.ts`:
- Around line 68-78: Remove the redundant immediate overwrite of this.items by
deleting the initial this.items = []; so the property is initialized once with
the multi-line array; update the constructor or the class initializer in Monitor
(look for the this.items assignment in Monitor.ts) to only contain the single
multi-line this.items = [ "fps", "memory", "totalGraphicsMemory",
"textureMemory", "bufferMemory", "drawCall", "triangles", "webglContext" ]
assignment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: df108ed3-3017-4ab1-a1b9-eb682f72794d

📥 Commits

Reviewing files that changed from the base of the PR and between 762e826 and f6f817a.

📒 Files selected for processing (2)
  • packages/stats/src/Core.ts
  • packages/stats/src/Monitor.ts
💤 Files with no reviewable changes (1)
  • packages/stats/src/Core.ts

@cptbtptpbcptdtptp cptbtptpbcptdtptp merged commit 06a6dc3 into galacean:dev/2.0 Mar 9, 2026
2 of 3 checks passed
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