javascript-racer
                                
                                 javascript-racer copied to clipboard
                                
                                    javascript-racer copied to clipboard
                            
                            
                            
                        Game crash in background render
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);

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.
I made a workaround using try-catch... it only pass by the error, the game doesn't crash, but it is not the solution.