From 445c8ad1606cc9fc0b21c3892971a31c18d1de0d Mon Sep 17 00:00:00 2001 From: kenshin <420373550@qq.com> Date: Tue, 20 Apr 2021 15:43:31 +0800 Subject: [PATCH] avoid mesh data leak. (#8413) * release mesh data. * mesh maybe share with other object, so just modify the batch utils. * remove empty space. * remove empty space. --- cocos/3d/misc/batch-utils.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cocos/3d/misc/batch-utils.ts b/cocos/3d/misc/batch-utils.ts index a3fb17870d4..c67a4891021 100644 --- a/cocos/3d/misc/batch-utils.ts +++ b/cocos/3d/misc/batch-utils.ts @@ -102,13 +102,18 @@ export class BatchingUtility { * @param batchedRoot the target output node */ public static unbatchStaticModel (staticModelRoot: Node, batchedRoot: Node) { - const models = staticModelRoot.getComponentsInChildren('cc.MeshRenderer'); + const models = staticModelRoot.getComponentsInChildren(MeshRenderer); for (let i = 0; i < models.length; i++) { const comp = models[i]; comp.enabled = true; } - const batchedModel = batchedRoot.getComponent('cc.MeshRenderer'); - if (batchedModel) { batchedModel.destroy(); } + const batchedModel = batchedRoot.getComponent(MeshRenderer); + if (batchedModel) { + if (batchedModel.mesh) { + batchedModel.mesh.destroyRenderingMesh(); + } + batchedModel.destroy(); + } return true; } }