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

View / safeguard against negative hint values to avoid unexpected behaviour #14545

Merged
merged 1 commit into from
Mar 2, 2023

Conversation

jahow
Copy link
Contributor

@jahow jahow commented Mar 1, 2023

This could happen e.g. in case view.endInteraction() was used too many times, which then might cause unexpected behaviours in dependent logic such as the webgl points renderer.

Fixes #14544

@github-actions
Copy link

github-actions bot commented Mar 1, 2023

📦 Preview the website for this branch here: https://deploy-preview-14545--ol-site.netlify.app/.

@jahow jahow force-pushed the webgl-points-allow-end-interaction branch from 72b5908 to 54c88fb Compare March 1, 2023 19:20
Copy link
Member

@ahocevar ahocevar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @jahow for taking a stab at this. It looks like your fix is a cure for the symptoms, but not for the root of the problem. In the first place. the view hints should never have a negative value. I'm not sure if it is enough to change endInteractionInternal() to not go below zero, or if the observed behavior is a sign of a more severe problem.

For now, it would probably be ok to safeguard the hints against going below zero, but I'd sleep better if interaction handling would work in a way that the hints would never go below zero without a safeguard.

@jahow
Copy link
Contributor Author

jahow commented Mar 1, 2023

IIRC the endInteraction method wasn't meant to be called from the application code, but only used by actual interactions such as zoom, pan etc. to signal to the view that it could go back to a stable state. Maybe a better, non public API should be used for this? I don't have much ideas for now.

I agree that this fix isn't great -- especially because other parts of the lib also rely on view hints being specifically zero instead of zero and less.

@ahocevar
Copy link
Member

ahocevar commented Mar 1, 2023

Ah, I see now! I hadn't read the original issue closely enough. So for this case, I think it is enough to safeguard endInteraction() against going below zero. I agree that it shouldn't be an API method, but now that it is, that would be the most sensible fix I think.

@jahow jahow force-pushed the webgl-points-allow-end-interaction branch from 54c88fb to 1f8f188 Compare March 2, 2023 08:16
@jahow
Copy link
Contributor Author

jahow commented Mar 2, 2023

I modified the PR to add the safeguard at the View level which is indeed a much more generic fix.

@jahow jahow changed the title WebGL Points / handle negative View hints View / safeguard against negative hint values to avoid unexpected behaviour Mar 2, 2023
Copy link
Member

@ahocevar ahocevar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better place to add a safeguard would be the API method endInteraction(), by means of checking for getInteracting() . Internally, I hope/think we do things correctly, and we could add a test to ensure that the hint is always >= 0. Otherwise I fear this is prone to problems that are hard to debug.

@jahow jahow force-pushed the webgl-points-allow-end-interaction branch 2 times, most recently from afbc124 to abe5289 Compare March 2, 2023 11:33
This could happen in case `view.endInteraction()` was called too many times,
which might cause unexpected behaviours with logic relying on hints being
zero or more.
@jahow jahow force-pushed the webgl-points-allow-end-interaction branch from abe5289 to 49f1fe0 Compare March 2, 2023 11:37
@jahow
Copy link
Contributor Author

jahow commented Mar 2, 2023

@ahocevar went with your suggestion! I think this contributes to make the view API safer to use.

@M393
Copy link
Contributor

M393 commented Mar 2, 2023

OpenLayers could output a warning in this case. It's a bug in application code, but maybe shouldn't be ignored silently.

Copy link
Member

@ahocevar ahocevar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, this looks great now. Thanks, @jahow !

@jahow
Copy link
Contributor Author

jahow commented Mar 2, 2023

OpenLayers could output a warning in this case. It's a bug in application code, but maybe shouldn't be ignored silently.

I think making it more permissive is not unreasonable, people might end up writing custom interactions which use begin/endInteraction liberally and calling endInteraction too many times shouldn't cause any serious issue with this PR.

@jahow jahow merged commit 71a9bd1 into openlayers:main Mar 2, 2023
@jahow jahow deleted the webgl-points-allow-end-interaction branch March 2, 2023 13:04
@tschaub
Copy link
Member

tschaub commented Mar 3, 2023

Apologies for approving without reading the existing discussion. I think this ended up in a good place.

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.

Change how viewNotMoving is calculated for PointsLayer
4 participants