From a7219a77aaa4a0c60d7604c32cebfb017cde271a Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 30 Oct 2015 14:36:07 -0700 Subject: [PATCH] [core] Don't crash when removing a shape annotation whose layer was never created --- src/mbgl/annotation/annotation_manager.cpp | 4 +++- test/api/annotations.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index e82dbfe48..dd2579267 100644 --- a/src/mbgl/annotation/annotation_manager.cpp +++ b/src/mbgl/annotation/annotation_manager.cpp @@ -131,7 +131,9 @@ void AnnotationManager::updateStyle(Style& style) { } for (const auto& layer : obsoleteShapeAnnotationLayers) { - style.removeLayer(layer); + if (style.getLayer(layer)) { + style.removeLayer(layer); + } } obsoleteShapeAnnotationLayers.clear(); diff --git a/test/api/annotations.cpp b/test/api/annotations.cpp index a9667c434..737c5314c 100644 --- a/test/api/annotations.cpp +++ b/test/api/annotations.cpp @@ -164,6 +164,18 @@ TEST(Annotations, RemoveShape) { util::write_file("test/output/remove_shape.png", renderPNG(map)); } +TEST(Annotations, ImmediateRemoveShape) { + auto display = std::make_shared(); + HeadlessView view(display, 1); + DefaultFileSource fileSource(nullptr); + Map map(view, fileSource, MapMode::Still); + + map.removeAnnotation(map.addShapeAnnotation(ShapeAnnotation({}, {}))); + map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), ""); + + renderPNG(map); +} + TEST(Annotations, SwitchStyle) { auto display = std::make_shared(); HeadlessView view(display, 1);