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

Fixed race conditions in AnimatedRoute #246

Merged
merged 5 commits into from
Apr 29, 2024

Conversation

bramp
Copy link
Contributor

@bramp bramp commented Sep 23, 2023

There were two easy to trigger race conditions in AnimatedRoute:

  1. Due to timing, it was possible for pointAnnotationManager to be called before it was set.
  2. If PointAnnotations were clicked in quick succession a delayed animation would fail trying to update a old layer.

I fixed them, cleaned up the example, and cleaned up some related files.

There are however some subtle race conditions still, for example

if (await mapState.mapboxMap.style.styleSourceExists('source')) {
      await mapState.mapboxMap.style.removeStyleSource('source');
}

Could fail if the style is deleted between the styleSourceExists and removeStyleSource calls. However, I felt it was better to keep the code a little error prone, then to muddle a lot of mutex, or wrap everything in exception handling.

bramp and others added 5 commits September 23, 2023 16:03
…sly used both, and ' is preferred in the dart style guide.
…onsidered "dynamic", and improves IDE/linting.

This could be avoided by using `super.id` but that's not supported in Dart pre 2.17.0. I also didn't notice until finishing that these files are generated, but its unclear what
generates them.
…re it's been set.

This is due to pointAnnotationManager requiring async to load, and setStyle callback being
called before it loaded. The simpliest fix was just to move the setStyle callback code into
the _onMapCreated callback as it was possible to set everything up in there.

There is still a subtle race if a user presses car_detailed FloatingActionButton button. I
think the correct fix is to disable that button until loading is done.
…multiple times, the StyleLayer would be removed, but the Tween animation would still try and update it.

I also simplified the code a little, as the style was inconsient with above, and had a branch that could never be visited.
@bramp bramp requested review from a team as code owners April 29, 2024 18:41
@bramp bramp requested a review from maios April 29, 2024 18:41
@evil159 evil159 changed the base branch from main to bramp/animated_route April 29, 2024 18:42
@evil159 evil159 merged commit 7169f59 into mapbox:bramp/animated_route Apr 29, 2024
evil159 added a commit that referenced this pull request Apr 29, 2024
* Changed the file to consistently use ' instead of ". The file previously used both, and ' is preferred in the dart style guide.

* Listed the parameter's types in the constructor so they wouldn't be considered "dynamic", and improves IDE/linting.

This could be avoided by using `super.id` but that's not supported in Dart pre 2.17.0. I also didn't notice until finishing that these files are generated, but its unclear what
generates them.

* There is a race-condition where pointAnnotationManager is called before it's been set.

This is due to pointAnnotationManager requiring async to load, and setStyle callback being
called before it loaded. The simpliest fix was just to move the setStyle callback code into
the _onMapCreated callback as it was possible to set everything up in there.

There is still a subtle race if a user presses car_detailed FloatingActionButton button. I
think the correct fix is to disable that button until loading is done.

* Fixed another race condition, where if a PointAnnotation was clicked multiple times, the StyleLayer would be removed, but the Tween animation would still try and update it.

I also simplified the code a little, as the style was inconsient with above, and had a branch that could never be visited.

---------

Co-authored-by: Roman Laitarenko <roman.laitarenko@mapbox.com>
evil159 added a commit that referenced this pull request Apr 30, 2024
* Changed the file to consistently use ' instead of ". The file previously used both, and ' is preferred in the dart style guide.

* Listed the parameter's types in the constructor so they wouldn't be considered "dynamic", and improves IDE/linting.

This could be avoided by using `super.id` but that's not supported in Dart pre 2.17.0. I also didn't notice until finishing that these files are generated, but its unclear what
generates them.

* There is a race-condition where pointAnnotationManager is called before it's been set.

This is due to pointAnnotationManager requiring async to load, and setStyle callback being
called before it loaded. The simpliest fix was just to move the setStyle callback code into
the _onMapCreated callback as it was possible to set everything up in there.

There is still a subtle race if a user presses car_detailed FloatingActionButton button. I
think the correct fix is to disable that button until loading is done.

* Fixed another race condition, where if a PointAnnotation was clicked multiple times, the StyleLayer would be removed, but the Tween animation would still try and update it.

I also simplified the code a little, as the style was inconsient with above, and had a branch that could never be visited.

---------

Co-authored-by: Andrew Brampton <github@bramp.net>
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.

None yet

2 participants