playcanvas / playcanvas/engine
Error when destroying a child in initialize
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 16.8k
- Forks
- 2k
- Avg merge
- 4h 32m
- Merged PRs (30d)
- 222
Description
To reproduce setup an Entity in the Editor like so:
Parent
- Child1
- Child2
Disable the Parent.
Add a script to Child1 that destroys it in initialize like so:
TestScript.prototype.initialize = function () { this.entity.destroy(); }
Create another script to clone the parent like so:
var clone = Parent.clone();
clone.enabled = true;
this.app.root.addChild(clone);
Notice there is an error thrown because in pc.Entity#_notifyHierarchyStateChanged we loop through the children of an entity and since we destroy one of its children that loop is invalid.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at pc.Entity#_notifyHierarchyStateChanged and reproduce the setup with a disabled Parent, two children, and a Child1 script that destroys itself in initialize. Trace the child iteration during the cloned parent’s hierarchy notification; done means the clone can be enabled and added without an error when a child destroys itself.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100