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

Fix raster dem crash style reload #1717

Merged
merged 9 commits into from
Oct 5, 2022

Conversation

yunikkk
Copy link
Contributor

@yunikkk yunikkk commented Oct 3, 2022

Summary of changes

When we load styles many times in a row there's a possibility that style data : sources event from the previous style will arrive after new style has been started loading. Here we add the fix for it and actually wait for the style data : style event after the style load has been initiated and skip all the other events.

This is actually part of MAPSNAT-516 that couldn't be fixed in gl-native.

User impact (optional)

Pull request checklist:

  • Briefly describe the changes in this PR.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality. If tests were not written, please explain why.
  • Optimize code for java consumption (@JvmOverloads, @file:JvmName, etc).
  • Add example if relevant.
  • Document any changes to public APIs.
  • Run make update-api to update generated api files, if there's public API changes, otherwise the verify-api-* CI steps might fail.
  • Update CHANGELOG.md or use the label 'skip changelog', otherwise check changelog CI step will fail.
  • If this PR is a v10.[version] release branch fix / enhancement, merge it to main firstly and then port to v10.[version] release branch.

Fixes: < Link to related issues that will be fixed by this pull request, if they exist >

PRs must be submitted under the terms of our Contributor License Agreement CLA.

@yunikkk yunikkk requested a review from a team as a code owner October 3, 2022 12:19
@yunikkk yunikkk force-pushed the yds-fix-raster-dem-crash-style-reload branch from 8c56a31 to a4da67f Compare October 3, 2022 12:19
Copy link
Contributor

@kiryldz kiryldz left a comment

Choose a reason for hiding this comment

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

Could you please add

  • PR description
  • bug label
  • fix ktlint
  • add changelog

@yunikkk
Copy link
Contributor Author

yunikkk commented Oct 3, 2022

Could you please add

  • PR description
  • bug label
  • fix ktlint
  • add changelog

Sure, thanks for hint, pushed it quickly to run the tests

@yunikkk yunikkk force-pushed the yds-fix-raster-dem-crash-style-reload branch from a4da67f to 418dd48 Compare October 3, 2022 14:21
@yunikkk yunikkk requested review from kiryldz and a team October 3, 2022 14:59
CHANGELOG.md Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@yunikkk yunikkk requested review from alexshalamov and a team October 4, 2022 08:55
sdk/src/main/java/com/mapbox/maps/StyleObserver.kt Outdated Show resolved Hide resolved
terrainSource: String = "TERRAIN_SOURCE",
demSourceUri: String = "mapbox://mapbox.mapbox-terrain-dem-v1"
) {
mapboxMap.loadStyle(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:
maybe add extra delay? potentially we can have super fast internet and super fast device.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well worst case if it happens without any delay - then the crashes actually had happenned. Could you elaborate more why do you think delay is needed?

Copy link
Contributor

@alexander-kulikovskii alexander-kulikovskii Oct 4, 2022

Choose a reason for hiding this comment

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

Could you elaborate more why do you think delay is needed?

to guarantee a delay between different styles load and it can be reproducible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But we don't need a delay, that's the thing, for this specific test - it happens when there is no delay so that style load events could collide with higher probability

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean some delay in style loaded callbacks. To make listeners crossover effect more noticeable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, but they all are executed on the main thread - if I delay it they all will be delayed as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I can add bunch of randomly delayed calls, all right, no problem

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added 100 launches with random delay of 0-5 millis

@yunikkk yunikkk force-pushed the yds-fix-raster-dem-crash-style-reload branch from d69ac6f to 35ea25e Compare October 4, 2022 09:08
@yunikkk yunikkk requested review from kiryldz and a team October 4, 2022 09:08
yunikkk and others added 2 commits October 4, 2022 14:59
Co-authored-by: Kiryl Dzehtsiarenka <kiryl.dzehtsiarenka@mapbox.com>
@alexshalamov
Copy link

Would be nice to add a test for a following scenario (pseudo code):

map.loadStyle(URL) { DSL runtime modifications }
map.onStyleDataLoaded({
  map.loadStyleJson(InvalidStyleJSON)
})
// verify that original style (URL) is loaded and runtime modifications are applied 

@yunikkk
Copy link
Contributor Author

yunikkk commented Oct 4, 2022

Would be nice to add a test for a following scenario (pseudo code):

map.loadStyle(URL) { DSL runtime modifications }
map.onStyleDataLoaded({
  map.loadStyleJson(InvalidStyleJSON)
})
// verify that original style (URL) is loaded and runtime modifications are applied 

Such flow will not be handled correctly at the moment, turns out.
We only keep the latest loadStyle DSL settings, overwriting the previous ones.
Created a ticket to track MAPSSDK-124.

terrainSource: String = "TERRAIN_SOURCE",
demSourceUri: String = "mapbox://mapbox.mapbox-terrain-dem-v1"
) {
mapboxMap.loadStyle(
Copy link
Contributor

Choose a reason for hiding this comment

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

I mean some delay in style loaded callbacks. To make listeners crossover effect more noticeable.

@yunikkk yunikkk merged commit 7b95b9b into main Oct 5, 2022
@yunikkk yunikkk deleted the yds-fix-raster-dem-crash-style-reload branch October 5, 2022 12:03
yunikkk added a commit that referenced this pull request Oct 5, 2022
* Fix possible crash when terrain source is added multiple times using runtime Style DSL.

* Update changelog.

* ktlint.

* Fix tests.

* PR fixes.

* Fix integration test.

* Update CHANGELOG.md

Co-authored-by: Kiryl Dzehtsiarenka <kiryl.dzehtsiarenka@mapbox.com>

* Review fixes.

* Add test with delays.

* Add test with delays.

Co-authored-by: Kiryl Dzehtsiarenka <kiryl.dzehtsiarenka@mapbox.com>
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.

4 participants