Handle missing/undefined/null arguments in particleContainer.addChild()
See original GitHub issueI 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 DisplayObject
s and submit a PR if this is a feature that you want.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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.