@@ -121,7 +121,7 @@ export function attachThreeChild(parent: NgtInstanceNode, child: NgtInstanceNode
121
121
invalidateInstance ( parent ) ;
122
122
}
123
123
124
- export function removeThreeChild ( parent : NgtInstanceNode , child : NgtInstanceNode , dispose ?: boolean ) {
124
+ export function removeThreeChild ( child : NgtInstanceNode , parent ? : NgtInstanceNode , dispose ?: boolean ) {
125
125
const pLS = getLocalState ( parent ) ;
126
126
const cLS = getLocalState ( child ) ;
127
127
@@ -132,12 +132,14 @@ export function removeThreeChild(parent: NgtInstanceNode, child: NgtInstanceNode
132
132
pLS ?. remove ( child , 'objects' ) ;
133
133
pLS ?. remove ( child , 'nonObjects' ) ;
134
134
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
+ }
141
143
}
142
144
143
145
const isPrimitive = cLS ?. primitive ;
@@ -151,11 +153,13 @@ export function removeThreeChild(parent: NgtInstanceNode, child: NgtInstanceNode
151
153
queueMicrotask ( ( ) => child [ 'dispose' ] ( ) ) ;
152
154
}
153
155
154
- invalidateInstance ( parent ) ;
156
+ if ( parent ) {
157
+ invalidateInstance ( parent ) ;
158
+ }
155
159
}
156
160
157
161
function 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 ) ) ;
159
163
}
160
164
161
165
export function processThreeEvent (
0 commit comments