Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't unlisten image twice when disposing an ol.ImageTile #3360

Merged
merged 1 commit into from
Mar 18, 2015

Conversation

fredj
Copy link
Member

@fredj fredj commented Mar 17, 2015

Fixes #3325

@ahocevar
Copy link
Member

Your change implies that #disposeInternal() might be called more than once, which makes me suspicious. Do we call it manually somewhere?

@fredj
Copy link
Member Author

fredj commented Mar 17, 2015

If the ol.ImageTile is disposed after the image has loaded, calling this.unlistenImage_() raises an error because of this check

@elemoine
Copy link
Member

I have the same patch in one of branches. I think it is correct. We dispose of tiles in ol.TileCache#expireCache, and the cache may contain tiles that are still in the idle state.

@ahocevar
Copy link
Member

I still think that the underlying issue is somewhere else. So if you want to merge this, please add a BIG FAT TODO reminding us to investigate this properly.

@elemoine
Copy link
Member

I still think that the underlying issue is somewhere else.

I don't get it Andreas. disposeInternal calls unlistenImage_, which currently assumes that the image is in loading (or error) state. That assumption is wrong, as the image may be in idle or loaded state.

@fredj
Copy link
Member Author

fredj commented Mar 18, 2015

disposeInternal can't be called more that once; goog.Disposable#dispose is taking care of that.

The problem is that we may call unlistenImage_ more that once: in handleImageError_ / handleImageLoad_ and then in disposeInternal

@ahocevar
Copy link
Member

If the above reasoning is true, then the following - more straightforward - version of disposeInternal should fix the issue too:

ol.ImageTile.prototype.disposeInternal = function() {
  if (this.state == ol.TileState.LOADING || this.state == ol.TileState.ERROR) {
    this.unlistenImage_();
  }
  goog.base(this, 'disposeInternal');
};

Am I right?

@elemoine
Copy link
Member

Am I right?

Not quite, because handleImageError_ also calls unlistenImage_. So this should work:

ol.ImageTile.prototype.disposeInternal = function() {
  if (this.state == ol.TileState.LOADING) {
    this.unlistenImage_();
  }
  goog.base(this, 'disposeInternal');
};

@ahocevar
Copy link
Member

👍, the above would make me happy.

@fredj
Copy link
Member Author

fredj commented Mar 18, 2015

Eric's proposal is more explicit, will change

@fredj fredj force-pushed the dispose-imagetile branch from d0e0d99 to f474e7c Compare March 18, 2015 09:33
@elemoine
Copy link
Member

Another option would be to change the unlistenImage_ function itself.

Instead of

/**
 * Discards event handlers which listen for load completion or errors.
 *
 * @private
 */
ol.ImageTile.prototype.unlistenImage_ = function() {
  goog.asserts.assert(!goog.isNull(this.imageListenerKeys_));
  goog.array.forEach(this.imageListenerKeys_, goog.events.unlistenByKey);
  this.imageListenerKeys_ = null;
};

it would be:

/**
 * Discards event handlers which listen for load completion or errors.
 *
 * @private
 */
ol.ImageTile.prototype.unlistenImage_ = function() {
  if (!goog.isNull(this.imageListenerKeys_)) {
    goog.array.forEach(this.imageListenerKeys_, goog.events.unlistenByKey);
    this.imageListenerKeys_ = null;
  }
};

@ahocevar
Copy link
Member

The previous proposal was more explicit. I always like to know the exact state from reading the code. Just checking whether there are still listeners registered does not look like an exact state to me.

@elemoine
Copy link
Member

The previous proposal was more explicit. I always like to know the exact state from reading the code. Just checking whether there are still listeners registered does not look like an exact state to me.

I see what you mean!

@fredj
Copy link
Member Author

fredj commented Mar 18, 2015

Thanks for the review

fredj added a commit that referenced this pull request Mar 18, 2015
Don't unlisten image twice when disposing an ol.ImageTile
@fredj fredj merged commit c707c5e into openlayers:master Mar 18, 2015
@fredj fredj deleted the dispose-imagetile branch March 18, 2015 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tilecache > DEFAULT_TILE_CACHE_HIGH_WATER_MARK will show error
3 participants