Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] Failed sprite requests do not block tiles rendering #14605

Merged
merged 2 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ class ImageMissingTest {
var rule = ActivityTestRule(EspressoTestActivity::class.java)

private lateinit var mapView: MapView
private val latch = CountDownLatch(1)
private val latch = CountDownLatch(2)

@Test
fun testMissingImage() {
rule.runOnUiThread {
initMap().addOnStyleImageMissingListener {
initMap(styleJson).addOnStyleImageMissingListener {
assertEquals("missing-icon", it)
latch.countDown()
}
}

rule.runOnUiThread {
initMap(styleJsonInvalidSprite).addOnStyleImageMissingListener {
assertEquals("missing-icon", it)
latch.countDown()
}
Expand All @@ -38,9 +45,9 @@ class ImageMissingTest {
}
}

private fun initMap(): MapView {
private fun initMap(style :String): MapView {
mapView = rule.activity.findViewById(R.id.mapView)
mapView.getMapAsync { it.setStyle(Style.Builder().fromJson(styleJson)) }
mapView.getMapAsync { it.setStyle(Style.Builder().fromJson(style)) }
return mapView
}

Expand Down Expand Up @@ -87,5 +94,48 @@ class ImageMissingTest {
}]
}
"""

private const val styleJsonInvalidSprite = """
{
"version": 8,
"name": "Mapbox Streets",
"sprite": "mapbox://sprites/mapbox/invalid",
"glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf",
"sources": {
"point": {
"type": "geojson",
"data": {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [0, 0]
}
}
}
},
"layers": [{
"id": "bg",
"type": "background",
"paint": {
"background-color": "#f00"
}
}, {
"id": "point",
"type": "circle",
"source": "point",
"paint": {
"circle-radius": 100
}
}, {
"id": "icon",
"type": "symbol",
"source": "point",
"layout": {
"icon-image": "missing-icon"
}
}]
}
"""
}
}
}
3 changes: 3 additions & 0 deletions src/mbgl/style/style_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ void Style::Impl::onSpriteError(std::exception_ptr error) {
lastError = error;
Log::Error(Event::Style, "Failed to load sprite: %s", util::toString(error).c_str());
observer->onResourceError(error);
// Unblock rendering tiles (even though sprite request has failed).
spriteLoaded = true;
observer->onUpdate();
Copy link
Contributor

Choose a reason for hiding this comment

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

This will only unblock rendering in continuous mode. Still image mode will still fail because the onResourceError terminates the whole map render request.

}

void Style::Impl::onLayerChanged(Layer& layer) {
Expand Down