Jump to content

Can't destroy objects: "this.children is null"


Wanderer777
 Share

Recommended Posts

When trying to clean up my stage on game over, I loop through my game object groups and destroy all children inside explicitly. Then I destroy the (now empty) groups:

cleanGroup(Grp1); // Grp1 is child of Stage groupcleanGroup(Grp2); // Grp2 is child of Stage groupcleanGroup(Grp3), // Grp3 is child of Stage groupcleanGroup(Stage);var cleanGroup = function(Grp)    {    if (Grp.children)        {        while (Grp.children.length) Grp.removeChildAt(0).destroy();        }    Grp.destroy();    }

However, this always gives me a hole bunch of error messages like:

 

this.children is null

this.parent is null

o is null

 

The error messages are constantly repeating as if it where within a loop anywhere inside the Pixi render enginge.

 

Why is this and how could this be solved?

 

Do I need to destroy my created sprites and groups at all or is it enough just to remove all of my references to them and let the garbage collection do the rest? Would this be reliable?

 

 

Link to comment
Share on other sites

Could this be a synch problem with the internal Pixi render engine that still tries to access objects that already have been removed manually? I found a thread here that described exactly this behaviour in a previous Pixi version.

 

This just happens when I try to manually destroy (nested) objects. If I just unreference them and remove them from stage, everything seems ok -also garbage collection seems to take those objects into account.

 

So I assume it would be also ok NOT to destroy objects manually to clean up and just unreference / unparent them and let the garbage collection do it's thing?

Link to comment
Share on other sites

If you destroy them without removing them first, you could get an error. If you are removing, and doing it outside a render loop then that probably isn't the case. We don't cache the scene tree, it is walked each time.

 

So I assume it would be also ok NOT to destroy objects manually to clean up and just unreference / unparent them and let the garbage collection do it's thing?

 

That is the only way to destroy objects is manually, the GC can't help with WebGL memory. You must call destroy manually, that is why it is exposed.

Link to comment
Share on other sites

If you destroy them without removing them first, you could get an error. If you are removing, and doing it outside a render loop then that probably isn't the case. We don't cache the scene tree, it is walked each time.

 

So I assume the method I posted above should work. I can't see any reason why this would cause any interference.

 

And do we have to destroy every single object manually or would it be enough to destroy the parent group only? Does Pixi automatically destroy all of its children then?

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...