Jump to content

container.removeChildren causes error on render


coolblue
 Share

Recommended Posts

I need to do an update on a container of sprites, so I use container.removeChildren() to clean it out first.  Then I just add in the new sprites using container.addChild().

The container is inside another container.

Sometimes when I render after doing this I get the following error...

            DisplayObject.prototype.updateTransform = function() {                // create some matrix refs for easy access                var pt = this.parent.worldTransform;  //Uncaught TypeError: Cannot read property 'worldTransform' of null                var wt = this.worldTransform;
Uncaught TypeError: Cannot read property 'worldTransform' of null  24.DisplayObject.updateTransform @ pixi.js:7698  23.Container.updateTransform @ pixi.js:7198  23.Container.updateTransform @ pixi.js:7201  48.WebGLRenderer.render @ pixi.js:13790  Renderer.draw @ index.html:626  tick @ index.html:236  event @ d3.min.js:549  tick @ d3.min.js:6651  d3_timer_mark @ d3.min.js:2486  d3_timer_step @ d3.min.js:2466

The this context is the sprite, it seems like maybe a deleted sprite is being rendered and because removeChildren sets the parent of the removed children to null this happens.

 

It happens seldom when I have the dev tools open (I'm working in chrome) but it happens every time when the devtools are closed (and the thing is cycling much faster).

 

Is it possible that the delete event emitted by removeChildren on delete is not propagating fast enough?

 

  1. Is this a known issue with removeChildren?
  2. Is there a better way to manage the process of updating a container of sprites with a dynamic population?

I tried hacking around it by only removing the excess sprites and then doing this...

circles.removeChildAt(i);circles.addChildAt(circle, i);

but I still got the same error.

Link to comment
Share on other sites

Are you doing the children modifications during a render loop? Like for example during updateTransform or a render function? That will cause this error.

 

Other than that, this shouldn't be possible if the tree is modified outside of the render loop. We don't cache what objects are in the scene tree, we iterate the children array of objects everytime. If they are modified outside that walk, then it shouldn't be possible to have this error. Adding a child manually to the children array without setting parent properly could also cause this, as well as adding a destroyed object or some such.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...