From 7fbbbea5f9df648505eac8669da2ce1f1ab18e5c Mon Sep 17 00:00:00 2001 From: Michal Dybizbanski Date: Thu, 28 Nov 2024 14:05:36 +0100 Subject: [PATCH] XEOK-169 Fix undefined this._entity.model --- src/viewer/scene/marker/Marker.js | 41 ++++++++++++++----------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/viewer/scene/marker/Marker.js b/src/viewer/scene/marker/Marker.js index 7277140e4..b0cbbc68f 100644 --- a/src/viewer/scene/marker/Marker.js +++ b/src/viewer/scene/marker/Marker.js @@ -191,25 +191,10 @@ class Marker extends Component { * @type {Entity} */ set entity(entity) { - if (this._entity) { - if (this._entity === entity) { - return; - } - if (this._onEntityDestroyed !== null) { - if (this._entity.model) { - this._entity.model.off(this._onEntityDestroyed); - } else { - this._entity.off(this._onEntityDestroyed); - } - this._onEntityDestroyed = null; - } - if (this._onEntityModelDestroyed !== null) { - if (this._entity.model) { - this._entity.model.off(this._onEntityModelDestroyed); - } - this._onEntityModelDestroyed = null; - } + if (this._entity === entity) { + return; } + this._cleanupDestroyedHandlers(); this._entity = entity; if (this._entity) { if (this._entity.isSceneModelEntity) { @@ -374,16 +359,28 @@ class Marker extends Component { this.fire("destroyed", true); this.scene.camera.off(this._onCameraViewMatrix); this.scene.camera.off(this._onCameraProjMatrix); + this._cleanupDestroyedHandlers(); + this._renderer.removeMarker(this); + super.destroy(); + } + + _cleanupDestroyedHandlers() { if (this._entity) { if (this._onEntityDestroyed !== null) { - this._entity.model.off(this._onEntityDestroyed); + if (this._entity.model) { + this._entity.model.off(this._onEntityDestroyed); + } else { + this._entity.off(this._onEntityDestroyed); + } + this._onEntityDestroyed = null; } if (this._onEntityModelDestroyed !== null) { - this._entity.model.off(this._onEntityModelDestroyed); + if (this._entity.model) { + this._entity.model.off(this._onEntityModelDestroyed); + } + this._onEntityModelDestroyed = null; } } - this._renderer.removeMarker(this); - super.destroy(); } }