I'm making a game using javascript + canvas. I use the code below to ensure
var imgLoaded = 0;
var imgToLoad = multiImgs;
var onImgLoad = function()
{
imgLoaded++;
if(imgLoaded == imgToLoad)
{
ctx.drawImage()
}
}
for(var i = 0; i < multiImgs; i++)
{
images[i] = new Image();
images[i].onload = onImgLoad();
images[i].src = 'images/'+i+'.png';
}
This code at times works fine, esp. when the images are cached. However, when loading for the first time, at times, it gives INDEX_SIZE_ERR: DOM Exception 1 which I found is due to height & width of image not being available as suggested by Quickredfox in this answer... but then here drawImage is called only when all the images are loaded? The error primarily occurs in mobile devices