Skip to content

Commit 37951a1

Browse files
authored
Fixed the issue where batch processing would be interrupted when some ui components were displayed or hidden (#18688)
1 parent 1d3785d commit 37951a1

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

cocos/2d/framework/ui-renderer.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,22 @@ export class UIRenderer extends Renderer {
385385
this._markForUpdateRenderData();
386386
}
387387

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+
388397
public onDisable (): void {
389398
this.node.off(NodeEventType.ANCHOR_CHANGED, this._nodeStateChange, this);
390399
this.node.off(NodeEventType.SIZE_CHANGED, this._nodeStateChange, this);
391400
this.node.off(NodeEventType.PARENT_CHANGED, this._colorDirty, this);
392401
// When disabling, it is necessary to free up idle space to fully utilize chunks
393402
// and avoid breaking batch processing.
394-
this.destroyRenderData();
403+
this._destroyData();
395404
uiRendererManager.removeRenderer(this);
396405
this._renderFlag = false;
397406
this._renderEntity.enabled = false;
@@ -402,13 +411,7 @@ export class UIRenderer extends Renderer {
402411
if (this.node._uiProps.uiComp === this) {
403412
this.node._uiProps.uiComp = null;
404413
}
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();
412415
}
413416

414417
/**

0 commit comments

Comments
 (0)