@@ -385,13 +385,22 @@ export class UIRenderer extends Renderer {
385
385
this . _markForUpdateRenderData ( ) ;
386
386
}
387
387
388
+ private _destroyData ( ) : void {
389
+ this . destroyRenderData ( ) ;
390
+ if ( this . _materials ) {
391
+ for ( let i = 0 ; i < this . _materials . length ; i ++ ) {
392
+ this . setSharedMaterial ( null , i , true ) ;
393
+ }
394
+ }
395
+ }
396
+
388
397
public onDisable ( ) : void {
389
398
this . node . off ( NodeEventType . ANCHOR_CHANGED , this . _nodeStateChange , this ) ;
390
399
this . node . off ( NodeEventType . SIZE_CHANGED , this . _nodeStateChange , this ) ;
391
400
this . node . off ( NodeEventType . PARENT_CHANGED , this . _colorDirty , this ) ;
392
401
// When disabling, it is necessary to free up idle space to fully utilize chunks
393
402
// and avoid breaking batch processing.
394
- this . destroyRenderData ( ) ;
403
+ this . _destroyData ( ) ;
395
404
uiRendererManager . removeRenderer ( this ) ;
396
405
this . _renderFlag = false ;
397
406
this . _renderEntity . enabled = false ;
@@ -402,13 +411,7 @@ export class UIRenderer extends Renderer {
402
411
if ( this . node . _uiProps . uiComp === this ) {
403
412
this . node . _uiProps . uiComp = null ;
404
413
}
405
- this . destroyRenderData ( ) ;
406
- if ( this . _materialInstances ) {
407
- for ( let i = 0 ; i < this . _materialInstances . length ; i ++ ) {
408
- const instance = this . _materialInstances [ i ] ;
409
- if ( instance ) { instance . destroy ( ) ; }
410
- }
411
- }
414
+ this . _destroyData ( ) ;
412
415
}
413
416
414
417
/**
0 commit comments