fixed the error in the clear operation (#6683)

This commit is contained in:
JoneLau
2020-05-17 12:55:16 +08:00
committed by GitHub
parent 1ff503bbf6
commit 3fb6490a64
2 changed files with 9 additions and 5 deletions
@@ -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;
+8 -4
View File
@@ -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;
}
}
}