Internal Component._setActive can be accidentally overridden by user Script
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 54/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- typescript
- Ambito
- backend
Direzione di ricerca
Read packages/core/src/Component.ts and packages/core/src/Entity.ts, especially the lifecycle call sites linked in the issue; then find the core regression-test conventions. Add a focused test for a Script with a string-keyed _setActive helper, covering component and hierarchy activation plus onAwake and onEnable. Done means the helper is not invoked by Engine lifecycle calls, while the virtual hooks still work and public declarations remain unchanged.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
A user Script can accidentally override the Engine's internal Component._setActive(value, activeChangeFlag) method with an unrelated helper of the same name. Entity currently invokes the method through normal JavaScript dynamic dispatch, so the user method receives Engine lifecycle arguments and can crash project startup.
This has occurred twice in independent scripts on @galacean/[email protected] (GameManager and UIController).
To Reproduce
import { Entity, Script } from "@galacean/engine";
export default class UIController extends Script {
private _setActive(entity: Entity | null, active: boolean): void {
if (entity) entity.isActive = active;
}
}
entity.addComponent(UIController);
Entity.addComponent() calls:
component._setActive(true, ActiveChangeFlag.All);
Because TypeScript private is emitted as a normal string-keyed prototype method, the call dispatches to UIController._setActive. The boolean true is then treated as an Entity, producing:
TypeError: Cannot create property 'isActive' on boolean 'true'
at UIController._setActive
at Entity.addComponent
Current source locations:
Why TypeScript does not catch it
_setActive is marked @internal, and packages/core/tsconfig.json enables stripInternal. The published Component.d.ts therefore contains no _setActive member, so strict consumer typechecking sees the user helper as a new private method rather than an override.
Expected behavior
Internal non-virtual lifecycle operations must not be overrideable by consumer Script members. A user helper named _setActive should not corrupt component activation, while intentionally virtual Engine hooks such as _onAwake and _onEnable must keep their existing behavior.
Suggested ownership boundary
Give this non-virtual operation a package-internal unique Symbol identity and let Entity call it through that identity. The symbol can be imported directly between core modules without being re-exported from packages/core/src/index.ts; @internal + stripInternal can keep the public declarations unchanged. This encodes non-overridability once and does not reserve the string _setActive in user scripts.
A focused regression should add a Script with an unrelated string-keyed _setActive helper, then verify that addComponent, hierarchy activation, onAwake, and onEnable still work and the user helper is not invoked by the Engine.
Environment
- Engine:
2.0.0-alpha.43 - Branch/source checked:
dev/2.0@490d2bc8ca1f1c187a995da3c913e59c56959a30 - Browser: Chromium-based runtime
- OS-specific: No
Screenshots
N/A — the failure occurs before window.engine is created.
- Lingua principale
- TypeScript
- Stelle
- 5.9k
- Fork
- 413
- Merge medio
- 16h 17m
- PR unite (30g)
- 41
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di galacean/engine
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
I maintainer di solito rispondono entro 1 giorno
-
RFC: Adopt Unity-style Collider components and hierarchical Rigidbody ownershipForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
I maintainer di solito rispondono entro 1 giorno
-
SkinnedMeshRenderer should derive default rootBone-space localBounds from mesh and skinForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaenhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di galacean/engine
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
e2e-failure ready-to-code
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
redhat-developer/rhdh-plugin-export-overlays#4794 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
area: plugins documentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
CatVinci-Studio/Textus#727 ·
I maintainer di solito rispondono entro 1 giorno