mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
fixed the error in the clear operation (#6683)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user