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

Uncaught TypeError: Cannot read property 'parentElement' of null #269

Open cannc4 opened 3 years ago

cannc4 commented 3 years ago

Hello, thanks a lot for creating this library!

I've been consistently hitting the following error when I try to do scale/wheel/pinch operations and wanted to report it

Uncaught TypeError: Cannot read property 'parentElement' of null
    at InteractionManager.push.../node_modules/@pixi/interaction/lib/interaction.es.js.InteractionManager.mapPositionToPoint (interaction.es.js:1611)
    at InputManager.getPointerPosition (viewport.es.js:172)
    at InputManager.handleWheel (viewport.es.js:191)
    at HTMLBodyElement.wheelFunction (viewport.es.js:41)

image

davidfig commented 3 years ago

Is your viewport.options.interaction set properly?

cannc4 commented 3 years ago

I am a bit unsure about the proper setting for that I am passing app.renderer.plugins.interaction to interaction object as far as I know

ShukantPal commented 3 years ago

This happens when you destroy your renderer and the viewport is still listening to the wheel event on the divWheel. You should add a listener to renderer destroy and destroy the viewport.

renderer.runners['destroy'].add({
  destroy: viewport.destroy.bind(viewport)
})
oddmj commented 3 years ago

in my case, I have the code invoke PIXI.Application instance's destroy() and encountered same error.

after change PIXI.Application instance's destroy method parameter, to destroy every children including viewport, seem to be solved for now.

app.destroy(boolean, {children: true});