sproutcore / sproutcore

JavaScript Application Framework - JS library only
sproutcore.com
Other
2.15k stars 290 forks source link

imageCache.releaseImage() does not abort active download #92

Closed bjwatson closed 14 years ago

bjwatson commented 14 years ago

Hello,

Thank you for this awesome Javascript framework. It has been a pleasure to learn and use it for a project that I'm working on.

I seem to have found my first true SproutCore bug (as opposed to a bug in my own code). There appears to be a broken method call in frameworks/foundation/system/image_cache.js. SC.imageCache._unscheduleImageEntry() makes a call to queue.image.abort(), in which queue.image appears to be null (or undefined).

This code path can be executed with:

var foo = function(url, imageOrError) { console.log('loaded image ' + url); } var url = SC.RunLoop.begin(); SC.imageCache.loadImage(url, null, foo); SC.RunLoop.end() SC.RunLoop.begin(); SC.imageCache.releaseImage(url, null, foo); SC.RunLoop.end()

This is a timing sensitive bug. If the releaseImage() call occurs while the image is actively loading, you will get "TypeError: Cannot call method 'abort' of undefined" on Chrome 7.0.517.41 for Mac OS 10.6.4. On Firefox 3.6.10 with Firebug 1.5.4 (same Mac platform), you get "TypeError: queue.image is undefined". I assume a similar error occurs on other browsers / platforms.

I tested this on Sproutcore 1.4.3.

I tried commenting out the queue.image.abort() line as a workaround, but then I see "Internal Inconsistency" errors during subsequent imageCache calls, so it appears that this line is supposed to call some important clean-up code.

Any ideas what this method call should be?

Best regards, Brian

bjwatson commented 14 years ago

Correction: the workaround of commenting out the queue.image.abort() line is fine. The "Internal Inconsistency" resulted from a bug in my application code. The stripped-down unit test above works fine when the queue.image.abort() line is commented out.

I'm able to make forward progress with this workaround. The purpose of this bug report is for the Sproutcore team to determine whether this line of code has any value, and if so, what should it really be?

Best regards, Brian