From 5efab6d032bd3653105d1d8f5aa44ba87efef781 Mon Sep 17 00:00:00 2001 From: Myway Date: Fri, 6 Aug 2021 15:30:59 +0800 Subject: [PATCH] fix terrain brush pass error by material gc (#9125) Co-authored-by: Myway3D1 <404793124@qq.com> --- cocos/terrain/terrain.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cocos/terrain/terrain.ts b/cocos/terrain/terrain.ts index 31e419bc65..f0ded493e7 100644 --- a/cocos/terrain/terrain.ts +++ b/cocos/terrain/terrain.ts @@ -209,6 +209,16 @@ class TerrainRenderable extends RenderableComponent { return; } + if (this._brushMaterial !== null && this._brushMaterial.passes !== null && this._brushMaterial.passes.length > 0) { + const passes = this._currentMaterial.passes; + for (let i = 0; i < passes.length; ++i) { + if (passes[i] === this._brushMaterial.passes[0]) { + passes.pop(); + break; + } + } + } + this._clearMaterials(); this._currentMaterial = null; @@ -557,8 +567,8 @@ export class TerrainBlock { public setBrushMaterial (mtl: Material|null) { if (this._renderable._brushMaterial !== mtl) { - this._renderable._brushMaterial = mtl; this._renderable._invalidMaterial(); + this._renderable._brushMaterial = mtl; } }