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

Make sure to always reset _enforcingBounds. #4089

Merged
merged 2 commits into from
Dec 28, 2015

Conversation

perliedman
Copy link
Member

In some cases, the flag _enforcingBounds was not reset, especially now that we exit early when center and newCenter is equal.

This PR wraps the logic in a try-finally-block to make sure the flag is always reset.

Even in case of early exit or exception.

Fixes #3938.
@perliedman perliedman force-pushed the always-reset-enforcing-bounds branch from b514e2b to b6c87c3 Compare December 14, 2015 12:46
@IvanSanchez
Copy link
Member

Wouldn't it be easier to just ... ?

if (center.equals(newCenter)) { 
  this._enforcingBounds = false;
  return this;
}

@perliedman
Copy link
Member Author

Sure, it's a matter of taste I guess.

Personally, I like try-finally to avoid the duplicate flag reset (it must be reset for normal exit as well) and also always making sure the flag is reset no matter what , even if something throws an exception in there, but I guess the advantage of that can be debated.

It might be that try-finally is more common in C#/Java. It appears this is the first time finally is used in Leaflet, so perhaps better to do it your way?

@yohanboniface
Copy link
Member

Even if the try/finally is more elegant, afaik it's not optimizable (see https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#2-unsupported-syntax for example), so I'd duplicate the reset as for now.

@perliedman
Copy link
Member Author

Ok, removed the try-finally, hope this looks alright now!

@yohanboniface interesting point regarding optimization, will keep that in mind (although this code is not on any performance critical path, as I understand it).

yohanboniface added a commit that referenced this pull request Dec 28, 2015
Make sure to always reset _enforcingBounds.
@yohanboniface yohanboniface merged commit 748ae53 into master Dec 28, 2015
@yohanboniface yohanboniface deleted the always-reset-enforcing-bounds branch December 28, 2015 15:43
@yohanboniface
Copy link
Member

Nice turnaround :)

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.

3 participants