July 7, 2008 at 8:47 pm
I pushed out a Sunset update today, this one affects an issue that occured with Firefox 3. Under said browser, the game would fail to load all the way if the user attempted to reload the game using the browser's reload button while already on the game page.
I'm not sure what caused the problem to occur, though I feel pretty safe calling it a Firefox 3 bug. Essentially, one of the first images in the preloaded image list would fail to load. It wasn't always the same image, but the loader would always fail to load exactly one image.
The loader works by creating a large number of HTML image elements and attempting to load them all at once. When asked to load n elements, browsers usually won't attempt to actually load all n at once, but rather more like 2 or 3 to avoid swamping both the user's and the internet server's connections. The browser will simply queue up the elements it needs to load, start loading a few, and then load more as items finish loading. The loader allows the browser to decide how many elements to load simultaneously.
The fix I implemented causes Firefox 3 (and only Firefox 3; not Firefox 2, Safari 3, or Mobile Safari) to operate under a different loading philosophy: it'll only attempt to load a single image at a time, and won't start loading the next image until the current one has finished loading. This causes loading to be much slower under Firefox 3, but I felt a slower load was preferable to no load at all.
July 7, 2008 at 11:24 pm
I just had a quick look at your code, and it's *possible* that you were actually running into an issue with the load completing before you set the onload handler. So the code in Loader.js
img.src = images[i];
img.onload = function() {
imagesLoaded++;
progress(imagesLoaded / imageCount);
if(imagesLoaded == imageCount) {
complete(imageObjects);
}
}
should be reordered to
img.onload = function() {
imagesLoaded++;
progress(imagesLoaded / imageCount);
if(imagesLoaded == imageCount) {
complete(imageObjects);
}
}
img.src = images[i];
I imagine that will make your loading issue go away in firefox 3
July 8, 2008 at 10:42 am
Actually, I tried that first, 'cause I've known Opera to have issues with exactly that problem. Trying it didn't fix it, though, so I continued working until I arrived at what I did.
For safety's sake, though, I might as well move that line of code below where I set the onload handler, just in case any future iterations of Safari or Firefox decide to be picky about it.
Heh, browsers really weren't meant to do what I do to them ^_^.