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

Canvas Tutorial, Images aren't always loaded before drawing to the canvas #30782

Closed
MelissaLarsonHarney opened this issue Dec 4, 2023 · 1 comment · Fixed by #32802
Closed
Labels
accepting PR Feel free to open a PR to resolve this issue Content:WebAPI Web API docs

Comments

@MelissaLarsonHarney
Copy link

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Using_images

What specific section or headline is this issue about?

"Example: Framing and Image" and "Art Gallery Example"

What information was incorrect, unhelpful, or incomplete?

The images aren't checked to see if they're loaded before drawing to the canvas(es). This means that sometimes only a few images draw, sometimes none of the images in the examples draw. The first time I loaded the page, the art gallery example didn't draw the pictures or frames. This issue also happens if you click 'play' to open the examples in the Playground.

image

image

What did you expect to see?

The pictures drawing properly to the canvas.

Do you have any supporting links, references, or citations?

No response

Do you have anything more you want to share?

I'm not sure if there is a better way to do this but, you could add an event listener to the window checking that it's been loaded before calling the draw() function?

window.addEventListener("load", (event) => {
draw();
});

MDN metadata

Page report details
@MelissaLarsonHarney MelissaLarsonHarney added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Dec 4, 2023
@github-actions github-actions bot added the Content:WebAPI Web API docs label Dec 4, 2023
@bsmth bsmth added accepting PR Feel free to open a PR to resolve this issue and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Jan 31, 2024
@bsmth
Copy link
Member

bsmth commented Jan 31, 2024

Thanks a lot for raising this one, I can also reproduce this. It might be good to use image.complete for this to check if an image is loaded and draw it, otherwise image.onload / addEventListener. I didn't have much luck with window.addEventListener("load"...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting PR Feel free to open a PR to resolve this issue Content:WebAPI Web API docs
2 participants