question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle missing/undefined/null arguments in particleContainer.addChild()

See original GitHub issue

I add a lot of children programmatically with the spread argument like particleContainer.addChild(...arrayOfChildren). Sometimes this results in an array with null/undefined or sometimes an empty arguments list which causes this error:

TypeError: Cannot read property 'parent' of undefined
    at ParticleContainer.addChild

I think addChild should handle these arguments gracefully and simply discard those arguments that it can’t process instead of throwing an error.

I can add some more isolated tests for other DisplayObjects and submit a PR if this is a feature that you want.

Fiddle

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
themoonratcommented, Sep 15, 2017

Correct, it won’t be fixed

You see, nicely handling garbage input in this case leads down a very deep rabbit hole of protecting against garbage input for all public APIs within pixi. What if I try to assign a texture property a number instead of a PIXI.Texture? What if I pass an array of booleans as a parameter for text colour? Etc. Etc. There are so so many things you could do to break the libs that goes beyond your use case, and so much extra defensive code would be required that I can’t see anyone creating PR for soon! And some may make the point that all that defensive code everywhere may effect performance. I don’t know the other guys opinions on this.

The solution that exists right now to help cover this… use Typescript, and let it’s compiler do that kind of type checking for you. In your case, you’d have to declare that your array may contain null/undefined entries, which is incompatible with the api

0reactions
lock[bot]commented, Feb 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle missing/undefined/null arguments in particleContainer ...
I add a lot of children programmatically with the spread argument like particleContainer.addChild(...arrayOfChildren).
Read more >
PIXI.ParticleContainer - PixiJS API Documentation
Documentation for PixiJS library.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found