From 3fb6490a64e21dcddeccdb516df23a4f34dffb56 Mon Sep 17 00:00:00 2001 From: JoneLau <32630749+JoneLau@users.noreply.github.com> Date: Sun, 17 May 2020 12:55:16 +0800 Subject: [PATCH] fixed the error in the clear operation (#6683) --- .../assembler/graphics/webgl/graphics-assembler.ts | 2 +- cocos/ui/components/graphics-component.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cocos/ui/assembler/graphics/webgl/graphics-assembler.ts b/cocos/ui/assembler/graphics/webgl/graphics-assembler.ts index faab508acd..f0e5d67540 100644 --- a/cocos/ui/assembler/graphics/webgl/graphics-assembler.ts +++ b/cocos/ui/assembler/graphics/webgl/graphics-assembler.ts @@ -173,7 +173,7 @@ export const graphicsAssembler: IAssembler = { }, end (graphics: GraphicsComponent) { - if (graphics.model) { + if (graphics.model && graphics.model.inited) { graphics.model.destroy(); } const impl = graphics.impl; diff --git a/cocos/ui/components/graphics-component.ts b/cocos/ui/components/graphics-component.ts index 909786a8fc..8dded75e73 100644 --- a/cocos/ui/components/graphics-component.ts +++ b/cocos/ui/components/graphics-component.ts @@ -504,10 +504,10 @@ export class GraphicsComponent extends UIRenderComponent { } this.impl.clear(clean); - if (this.model) { + this._detachFromScene(); + if(this.model){ this.model.destroy(); } - this.markForUpdateRenderData(); } @@ -535,6 +535,7 @@ export class GraphicsComponent extends UIRenderComponent { * 根据当前的画线样式,绘制当前或已经存在的路径。 */ public stroke () { + this._attachToScene(); (this._assembler as IAssembler).stroke!(this); } @@ -546,6 +547,7 @@ export class GraphicsComponent extends UIRenderComponent { * 根据当前的画线样式,填充当前或已经存在的路径。 */ public fill () { + this._attachToScene(); (this._assembler as IAssembler).fill!(this); } @@ -601,10 +603,11 @@ export class GraphicsComponent extends UIRenderComponent { protected _attachToScene () { const scene = director.root!.ui.renderScene; - if (!this.model) { + if (!this.model || this.model!.scene === scene) { return; } - if (this.model!.scene != null) { + + if (this.model!.scene !== null) { this._detachFromScene(); } scene.addModel(this.model!); @@ -613,6 +616,7 @@ export class GraphicsComponent extends UIRenderComponent { protected _detachFromScene () { if (this.model && this.model.scene) { this.model.scene.removeModel(this.model); + this.model.scene = null; } } }