@@ -121,7 +121,7 @@ export function attachThreeChild(parent: NgtInstanceNode, child: NgtInstanceNode
121121 invalidateInstance ( parent ) ;
122122}
123123
124- export function removeThreeChild ( parent : NgtInstanceNode , child : NgtInstanceNode , dispose ?: boolean ) {
124+ export function removeThreeChild ( child : NgtInstanceNode , parent ? : NgtInstanceNode , dispose ?: boolean ) {
125125 const pLS = getLocalState ( parent ) ;
126126 const cLS = getLocalState ( child ) ;
127127
@@ -132,12 +132,14 @@ export function removeThreeChild(parent: NgtInstanceNode, child: NgtInstanceNode
132132 pLS ?. remove ( child , 'objects' ) ;
133133 pLS ?. remove ( child , 'nonObjects' ) ;
134134
135- if ( cLS ?. attach ) {
136- detach ( parent , child , cLS . attach ) ;
137- } else if ( is . object3D ( parent ) && is . object3D ( child ) ) {
138- parent . remove ( child ) ;
139- const store = cLS ?. store || pLS ?. store ;
140- if ( store ) removeInteractivity ( store , child ) ;
135+ if ( parent ) {
136+ if ( cLS ?. attach ) {
137+ detach ( parent , child , cLS . attach ) ;
138+ } else if ( is . object3D ( parent ) && is . object3D ( child ) ) {
139+ parent . remove ( child ) ;
140+ const store = cLS ?. store || pLS ?. store ;
141+ if ( store ) removeInteractivity ( store , child ) ;
142+ }
141143 }
142144
143145 const isPrimitive = cLS ?. primitive ;
@@ -151,11 +153,13 @@ export function removeThreeChild(parent: NgtInstanceNode, child: NgtInstanceNode
151153 queueMicrotask ( ( ) => child [ 'dispose' ] ( ) ) ;
152154 }
153155
154- invalidateInstance ( parent ) ;
156+ if ( parent ) {
157+ invalidateInstance ( parent ) ;
158+ }
155159}
156160
157161function removeThreeRecursive ( array : NgtInstanceNode [ ] , parent : NgtInstanceNode , dispose : boolean ) {
158- if ( array ) [ ...array ] . forEach ( ( child ) => removeThreeChild ( parent , child , dispose ) ) ;
162+ if ( array ) [ ...array ] . forEach ( ( child ) => removeThreeChild ( child , parent , dispose ) ) ;
159163}
160164
161165export function processThreeEvent (
0 commit comments