javascript-racer icon indicating copy to clipboard operation
javascript-racer copied to clipboard

Game crash in background render

Open MarioMey opened this issue 10 years ago • 2 comments

Sometimes, after 9 seconds of playing (the first curve to the left of the array of towers), all the sprites dissappear and I have this in Firefox console: IndexSizeError: Index or size is negative or greater than the allowed amount in common.js, line 287: ctx.drawImage(background, sourceX, sourceY, sourceW, sourceH, destX, destY, destW, destH);

captura de pantalla de 2015-06-01 09 25 08

MarioMey avatar Jun 03 '15 23:06 MarioMey

Before line 287, I added: console.log(background, sourceX, sourceY, sourceW, sourceH, destX, destY, destW, destH); to debug it. Before the bug arrived (at second 9.1), the last lines logged were: ... < img src="images/background.png"> 5 985 640 480 0 19.11709921839087 1024 768 < img src="images/background.png"> 5 495 640 480 0 6.397193056316348 1024 768 < img src="images/background.png"> 5 5 640 480 0 12.794386112632695 1024 768 < img src="images/background.png"> 1285 985 0 480 0 19.191579168949044 0 768 IndexSizeError: Index or size is negative or greater than the allowed amount

I don't understand so much... but it seems that drawImage does not accept 0 as destiny width... and Render.background is trying to do that.

MarioMey avatar Jun 03 '15 23:06 MarioMey

I made a workaround using try-catch... it only pass by the error, the game doesn't crash, but it is not the solution.

MarioMey avatar Jun 05 '15 20:06 MarioMey