Removing an obstacle crashes the raycaster
pierre-josselin opened this issue · comments
Description
Removing an obstacle causes the raycaster to crash.
Demo
I forked Phaser-raycaster - example 9 - field of view (v0.8 update)
and edited to destroy first obstacle on scene click:
https://codepen.io/pierre-josselin/pen/bGegjeO
Log
castCircle.js:46 Uncaught TypeError: Cannot read property 'get' of undefined
at i.s [as castCircle] (castCircle.js:46)
at initialize.<anonymous> (pen.js:91)
at initialize.h.emit (phaser.min.js:1)
at initialize.processMoveEvents (phaser.min.js:1)
at initialize.update (phaser.min.js:1)
at initialize.updateInputPlugins (phaser.min.js:1)
at initialize.onMouseMove (phaser.min.js:1)
at HTMLCanvasElement.onMouseMove (phaser.min.js:1)
Thank you for this plugin, it's awesome !
Problem fixed by using:
raycaster.removeMappedObjects(object);
Thank you for support.
Phaser-raycaster store references to mapped game objects internally.
Error you encountered occured because plugin tried to get map data from removed object.
As you figured out, to avoid this you need to remove object's mapping first with raycaster.removeMappedObjects(object)
(https://wiserim.github.io/phaser-raycaster/Raycaster.html#removeMappedObjects__anchor).