Browse Source

fix: safely remove helpers in vDistanceTo and vLightHelper directives

alvarosabu 3 months ago
parent
commit
d24d2e9d2a
2 changed files with 6 additions and 4 deletions
  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) => {
   unmounted: (el: TresObject) => {
     arrowHelper?.dispose()
     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`)
       logWarning(`${el.type} is not a light`)
       return
       return
     }
     }
-    currentInstance = el.parent.children.find((child: TresObject) => child instanceof CurrentHelper)
-
     if (currentInstance && currentInstance.dispose) {
     if (currentInstance && currentInstance.dispose) {
       currentInstance.dispose()
       currentInstance.dispose()
     }
     }
-    el.parent.remove(currentInstance)
+    if (el.parent) {
+      el.parent.remove(currentInstance)
+    }
   },
   },
 }
 }