From 2dbb7f5064c56a3c15741c8fd023d07c2c0ad209 Mon Sep 17 00:00:00 2001 From: Ander Conselvan de Oliveira Date: Mon, 4 Nov 2019 08:12:23 +0200 Subject: Fix MapSnapshotter build failure on Windows MSVC implementation of std::promise is buggy and only works with types that can be default-constructed. Wrap LatLngBounds in such a struct to avoid a compilation failure in the instantiation of ask() inside MapSnapshotter::getRegion() since that would create a std::promise. --- next/platform/linux/linux.cmake | 1 + next/test/CMakeLists.txt | 1 + platform/default/src/mbgl/map/map_snapshotter.cpp | 21 +++++++++++++++++---- test/map/snapshotter.test.cpp | 22 ++++++++++++++++++++++ test/test-files.json | 1 + 5 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 test/map/snapshotter.test.cpp diff --git a/next/platform/linux/linux.cmake b/next/platform/linux/linux.cmake index 396b9a0ffd..912fbd596c 100644 --- a/next/platform/linux/linux.cmake +++ b/next/platform/linux/linux.cmake @@ -17,6 +17,7 @@ target_sources( ${MBGL_ROOT}/platform/default/src/mbgl/gl/headless_backend.cpp ${MBGL_ROOT}/platform/default/src/mbgl/i18n/collator.cpp ${MBGL_ROOT}/platform/default/src/mbgl/i18n/number_format.cpp + ${MBGL_ROOT}/platform/default/src/mbgl/map/map_snapshotter.cpp ${MBGL_ROOT}/platform/default/src/mbgl/layermanager/layer_manager.cpp ${MBGL_ROOT}/platform/default/src/mbgl/storage/asset_file_source.cpp ${MBGL_ROOT}/platform/default/src/mbgl/storage/default_file_source.cpp diff --git a/next/test/CMakeLists.txt b/next/test/CMakeLists.txt index 4995fa4e56..0da9debaee 100644 --- a/next/test/CMakeLists.txt +++ b/next/test/CMakeLists.txt @@ -18,6 +18,7 @@ add_library( ${MBGL_ROOT}/test/gl/object.test.cpp ${MBGL_ROOT}/test/map/map.test.cpp ${MBGL_ROOT}/test/map/prefetch.test.cpp + ${MBGL_ROOT}/test/map/snapshotter.test.cpp ${MBGL_ROOT}/test/map/transform.test.cpp ${MBGL_ROOT}/test/math/clamp.test.cpp ${MBGL_ROOT}/test/math/minmax.test.cpp diff --git a/platform/default/src/mbgl/map/map_snapshotter.cpp b/platform/default/src/mbgl/map/map_snapshotter.cpp index 705a791af9..0c94eadc33 100644 --- a/platform/default/src/mbgl/map/map_snapshotter.cpp +++ b/platform/default/src/mbgl/map/map_snapshotter.cpp @@ -12,6 +12,17 @@ namespace mbgl { +/* + * MSVC implementation of std::promise is buggy and only works with types that can be default-constructed. + * Wrap LatLngBounds in such a struct to avoid a compilation failure in the instantiation of ask() inside + * MapSnapshotter::getRegion() since that would create a std::promise. + */ +struct RegionWrapper { + explicit RegionWrapper() : region(LatLngBounds::unbounded()) {} + + LatLngBounds region; +}; + class MapSnapshotter::Impl { public: Impl(const std::pair style, @@ -35,7 +46,7 @@ public: CameraOptions getCameraOptions() const; void setRegion(LatLngBounds); - LatLngBounds getRegion() const; + RegionWrapper getRegion() const; void snapshot(ActorRef); @@ -157,8 +168,10 @@ void MapSnapshotter::Impl::setRegion(LatLngBounds region) { map.jumpTo(map.cameraForLatLngs(latLngs, insets)); } -LatLngBounds MapSnapshotter::Impl::getRegion() const { - return map.latLngBoundsForCamera(getCameraOptions()); +RegionWrapper MapSnapshotter::Impl::getRegion() const { + RegionWrapper region; + region.region = map.latLngBoundsForCamera(getCameraOptions()); + return region; } MapSnapshotter::MapSnapshotter(const std::pair style, @@ -215,7 +228,7 @@ void MapSnapshotter::setRegion(const LatLngBounds& bounds) { } LatLngBounds MapSnapshotter::getRegion() const { - return impl->actor().ask(&Impl::getRegion).get(); + return impl->actor().ask(&Impl::getRegion).get().region; } } // namespace mbgl diff --git a/test/map/snapshotter.test.cpp b/test/map/snapshotter.test.cpp new file mode 100644 index 0000000000..8e6c8a4904 --- /dev/null +++ b/test/map/snapshotter.test.cpp @@ -0,0 +1,22 @@ +#include + +#include +#include +#include +#include + +using namespace mbgl; + +TEST(Snapshotter, Region) { + MapSnapshotter snapshotter({true, "{}"}, {256, 256}, 1.0, {}, {}, {}, {}); + + LatLngBounds region = LatLngBounds::hull({1.0, -1.0}, {-1.0, 1.0}); + snapshotter.setRegion(region); + + LatLngBounds region2 = snapshotter.getRegion(); + + EXPECT_NEAR(region.south(), region2.south(), 0.0001); + EXPECT_NEAR(region.north(), region2.north(), 0.0001); + EXPECT_NEAR(region.east(), region2.east(), 0.0001); + EXPECT_NEAR(region.west(), region2.west(), 0.0001); +} diff --git a/test/test-files.json b/test/test-files.json index a98e896e7e..293a0804e2 100644 --- a/test/test-files.json +++ b/test/test-files.json @@ -19,6 +19,7 @@ "test/gl/object.test.cpp", "test/map/map.test.cpp", "test/map/prefetch.test.cpp", + "test/map/snapshotter.test.cpp", "test/map/transform.test.cpp", "test/math/clamp.test.cpp", "test/math/minmax.test.cpp", -- cgit v1.2.1