Ver código fonte

fix: safely remove helpers in vDistanceTo and vLightHelper directives

alvarosabu 3 meses atrás
pai
commit
d24d2e9d2a
2 arquivos alterados com 6 adições e 4 exclusões
  1. 3 1
      src/directives/vDistanceTo.ts
  2. 3 3
      src/directives/vLightHelper.ts

+ 3 - 1
src/directives/vDistanceTo.ts

@@ -33,6 +33,8 @@ export const vDistanceTo = {
   },
   unmounted: (el: TresObject) => {
     arrowHelper?.dispose()
-    el.parent.remove(arrowHelper)
+    if (el.parent) {
+      el.parent.remove(arrowHelper)
+    }
   },
 }

+ 3 - 3
src/directives/vLightHelper.ts

@@ -51,11 +51,11 @@ export const vLightHelper = {
       logWarning(`${el.type} is not a light`)
       return
     }
-    currentInstance = el.parent.children.find((child: TresObject) => child instanceof CurrentHelper)
-
     if (currentInstance && currentInstance.dispose) {
       currentInstance.dispose()
     }
-    el.parent.remove(currentInstance)
+    if (el.parent) {
+      el.parent.remove(currentInstance)
+    }
   },
 }