0

I am making a space shooter-style game, and the code I have made so far was working 2 days ago but now I am getting this error:

Uncaught DOMException: CanvasRenderingContext2D.drawImage: Passed-in image is "broken"

here is some of the code. I define the image here:

const baddie = new Image();        
baddie.src = './space_shooter_baddie.jpg'; 

and I am getting an error on this line:

ctx.drawImage(baddie, 0, 0, 28, 28, badx[i],  bady[i], 28, 28);

could someone please tell me what this means? thank you.

note: I just tried with a different image and it worked. so it's probably not a code error.

Daniel Piñeiro
  • 3,009
  • 1
  • 16
  • 26
  • Either the image is corrupted, or you're trying to use it before it's fully loaded. – Teemu Mar 21 '22 at 05:12
  • I can't find this error message from the docs, which browser gives that? According to [the docs](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage#exceptions), `drawImage` throws only InvalidStateError. – Teemu Mar 21 '22 at 05:23
  • @Teemu InvalidStateError is a DOMException. – Kaiido Mar 22 '22 at 00:48
  • @Kaiido Yes, but it's not "_Passed-in image is "broken"_". Maybe it's a translation from some other language ..? – Teemu Mar 22 '22 at 05:36
  • @Teemu That's the message they pass, the UA has all the liberty to send whatever they wish in the message. (And FF does pass this message https://jsfiddle.net/6e5190wh/ ) – Kaiido Mar 22 '22 at 05:45

0 Answers0