Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Graphics.clear() doesn't clear active path #10550

Closed
AlexeyNigin opened this issue May 20, 2024 · 0 comments · Fixed by #10561
Closed

Bug: Graphics.clear() doesn't clear active path #10550

AlexeyNigin opened this issue May 20, 2024 · 0 comments · Fixed by #10561
Assignees

Comments

@AlexeyNigin
Copy link

Current Behavior

Graphics.clear() only clears paths that have already been drawn; if you were in the middle of defining a path, that active path is not reset by clear().

Expected Behavior

The active path should be cleared by Graphics.clear().

Steps to Reproduce

(async () => {
    // Initialize an app
    const app = new PIXI.Application();
    await app.init({ backgroundColor: 0x222222, resizeTo: window });
    document.body.appendChild(app.canvas);

    // Create a graphics object
    let graphic = new PIXI.Graphics();
    app.stage.addChild(graphic);

    // Start drawing a path, but don't finish it
    graphic
        .moveTo(100, 100)
        .lineTo(200, 200);

    // Clear!
    graphic.clear();

    // Draw something else
    // Note that the previous unfinished path wasn't cleared and still gets drawn
    graphic
        .circle(150, 150, 50)
        .stroke({ color: 0xffffff, width: 1 });
})();

Live example: https://pixiplayground.com/#/edit/cqyRtXSXO93cxK33CHSIK

Environment

Possible Solution

Soultion: In GraphicsCOntext.clear(), call this._activePath.clear();.

Workaround: don't clear() when the Graphics object has an active path.

Additional Information

I stumbled upon this issue when I erroneously put stroke()/fill() calls before shape-drawing calls - I am sure I am not the only one who did this after migrating to v8. clear() not clearing active paths made debugging my mistake more confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants