coolblue Posted September 17, 2015 Share Posted September 17, 2015 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:2466The 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? Is this a known issue with removeChildren? 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. Quote Link to comment Share on other sites More sharing options...
xerver Posted September 17, 2015 Share Posted September 17, 2015 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. Quote Link to comment Share on other sites More sharing options...
coolblue Posted September 18, 2015 Author Share Posted September 18, 2015 Yes, it was my own fault: I had a piece of code where I was man-handling sprites instead of using the child management functions of the container: bad idea! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.