Skip to content

Commit

Permalink
Unable to abort RawImageLoader requests ivmartel#583
Browse files Browse the repository at this point in the history
  • Loading branch information
frickt committed Oct 11, 2018
1 parent 2942679 commit efe99a6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ dwv.App = function ()
function handleAbort(error)
{
// log
if ( error.message ) {
if ( error && error.message ) {
console.warn(error.message);
}
else {
Expand Down
12 changes: 11 additions & 1 deletion src/io/rawImageLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ dwv.io.RawImageLoader = function ()
// closure to self
var self = this;

/**
* if abort is triggered, all image.onload callbacks have to be cancelled
* @type {boolean}
*/
var aborted = false;

/**
* Set the loader options.
* @param {Object} opt The input options.
Expand Down Expand Up @@ -55,6 +61,7 @@ dwv.io.RawImageLoader = function ()
* @param {Number} index The data index.
*/
this.load = function ( dataUri, origin, index ) {
aborted = false;
// create a DOM image
var image = new Image();
image.src = dataUri;
Expand All @@ -64,7 +71,9 @@ dwv.io.RawImageLoader = function ()
// triggered by ctx.drawImage
image.onload = function (/*event*/) {
try {
self.onload( dwv.image.getViewFromDOMImage(this) );
if(!aborted){
self.onload( dwv.image.getViewFromDOMImage(this) );
}
self.onloadend();
} catch (error) {
self.onerror(error);
Expand All @@ -78,6 +87,7 @@ dwv.io.RawImageLoader = function ()
* Abort load. TODO...
*/
this.abort = function () {
aborted = true;
self.onabort();
};

Expand Down
2 changes: 1 addition & 1 deletion src/io/urlsLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ dwv.io.UrlsLoader = function ()
// abort requests
for ( var i = 0; i < requests.length; ++i ) {
// 0: UNSENT, 1: OPENED, 2: HEADERS_RECEIVED (send()), 3: LOADING, 4: DONE
if ( requests[i].readyState === 2 || requests[i].readyState === 3 ) {
if ( requests[i].readyState !== 4 ) {
requests[i].abort();
}
}
Expand Down

0 comments on commit efe99a6

Please sign in to comment.