playcanvas / playcanvas/engine

Error when destroying a child in initialize

Open
#1,180 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.