From ae13853320a5b24f88b16292bfbe9e8df37cb7f3 Mon Sep 17 00:00:00 2001 From: Myway Date: Tue, 24 Nov 2020 09:52:18 +0800 Subject: [PATCH] fix terrain model render (#7847) Co-authored-by: Myway3D1 <404793124@qq.com> --- cocos/terrain/terrain.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cocos/terrain/terrain.ts b/cocos/terrain/terrain.ts index 40850d5dd3..4653e8a9fa 100644 --- a/cocos/terrain/terrain.ts +++ b/cocos/terrain/terrain.ts @@ -198,6 +198,14 @@ class TerrainRenderable extends RenderableComponent { return super.destroy(); } + public _destroyModel () { + // this._invalidMaterial(); + if (this._model != null) { + legacyCC.director.root.destroyModel(this._model); + this._model = null; + } + } + public _invalidMaterial () { if (this._currentMaterial == null) { return; @@ -399,6 +407,8 @@ export class TerrainBlock { } public destroy () { + this._renderable._destroyModel(); + if (this._node != null) { this._node.destroy(); } @@ -1228,6 +1238,11 @@ export class Terrain extends Component { } public onDestroy () { + for (const i of this._blocks) { + i.destroy(); + } + this._blocks = []; + for (let i = 0; i < this._layers.length; ++i) { this._layers[i] = null; }