Found the drawImage problem ...
2,735
1
Advertisement
Found the bug I wrote about in the last post: drawImage worked in Chrome, but Firefox showed a white image.
http://www.procgames.com/raidaces
I was completely on the wrong track when I noticed that it sometimes works in Firefox when I call the update function after waiting 5 seconds.
What surprised me was that every time it worked it rendered images with only brown tiles, so I abandoned that track (well, also because waiting 20seconds did not improve the odds at all).
Because I am really ... and I mean REALLY bad at google searches I suspected color profiles (hey, they were mentioned in a canvas related stackexchange discussion ...
along with green pixels ... can that be a coincidence?).
When I ruled those out I suspected caching ... that it somehow managed to render the all brown tiles images because one of them was cached at some point.
I confirmed that caches did play a role by using the reproducible way to generate maps. After a refresh, drawImage always worked and sometimes it even showed an old version of an image (not from the current map).
Of course it turned out to be the obvious thing. I need to wait for the load event of the image before I draw it to the canvas.
It is not that this thought had not crossed my mind right away when the error occurred ... for some reason I thought that was not relevant ... probably because I expected images to be transferred from canvas to img elements immediately - and in this case synchronously.
In hindsight it makes sense that the normal rules apply. After all, the image data is read using a dataURL.
http://www.procgames.com/raidaces
I was completely on the wrong track when I noticed that it sometimes works in Firefox when I call the update function after waiting 5 seconds.
What surprised me was that every time it worked it rendered images with only brown tiles, so I abandoned that track (well, also because waiting 20seconds did not improve the odds at all).
Because I am really ... and I mean REALLY bad at google searches I suspected color profiles (hey, they were mentioned in a canvas related stackexchange discussion ...
When I ruled those out I suspected caching ... that it somehow managed to render the all brown tiles images because one of them was cached at some point.
I confirmed that caches did play a role by using the reproducible way to generate maps. After a refresh, drawImage always worked and sometimes it even showed an old version of an image (not from the current map).
Of course it turned out to be the obvious thing. I need to wait for the load event of the image before I draw it to the canvas.
It is not that this thought had not crossed my mind right away when the error occurred ... for some reason I thought that was not relevant ... probably because I expected images to be transferred from canvas to img elements immediately - and in this case synchronously.
In hindsight it makes sense that the normal rules apply. After all, the image data is read using a dataURL.
Advertisement
Advertisement
Advertisement
Discussion