davidfig / pixi-viewport

A highly configurable viewport/2D camera designed to work with pixi.js
https://davidfig.github.io/pixi-viewport/
MIT License
1.04k stars 174 forks source link

Why I cannot destroy viewport on zoomed end event? #466

Open devexus opened 11 months ago

devexus commented 11 months ago

I want to change the view when I reach the set scale. I try to remove the viewport from the Pixi children and then run the destroy method. I received an error.

image

blnvdanil commented 11 months ago

Simply because events are fired synchronously, and inside of viewport it has some other code to do after it fired zoom-end event. Destroy method does something like this.transform = null on display object, but viewport accesses position of the object, which is null, after it fired the event, and we have cannot get properties of null exception