diff options
author | Ander Conselvan de Oliveira <ander.deoliveira@mapbox.com> | 2019-11-04 08:12:23 +0200 |
---|---|---|
committer | Ander Conselvan de Oliveira <ander.deoliveira@mapbox.com> | 2019-11-05 04:43:31 +0200 |
commit | 2dbb7f5064c56a3c15741c8fd023d07c2c0ad209 (patch) | |
tree | 0ad50e13c055be777a7978f9d41e3928d0fa91d8 | |
parent | d8b1b2bacf0dd9812d62077a825067441037791b (diff) | |
download | qtlocation-mapboxgl-upstream/anderco-win-snapshot.tar.gz |
Fix MapSnapshotter build failure on Windowsupstream/anderco-win-snapshot
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<LanLngBounds>.
-rw-r--r-- | next/platform/linux/linux.cmake | 1 | ||||
-rw-r--r-- | next/test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | platform/default/src/mbgl/map/map_snapshotter.cpp | 21 | ||||
-rw-r--r-- | test/map/snapshotter.test.cpp | 22 | ||||
-rw-r--r-- | test/test-files.json | 1 |
5 files changed, 42 insertions, 4 deletions
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<LanLngBounds>. + */ +struct RegionWrapper { + explicit RegionWrapper() : region(LatLngBounds::unbounded()) {} + + LatLngBounds region; +}; + class MapSnapshotter::Impl { public: Impl(const std::pair<bool, std::string> style, @@ -35,7 +46,7 @@ public: CameraOptions getCameraOptions() const; void setRegion(LatLngBounds); - LatLngBounds getRegion() const; + RegionWrapper getRegion() const; void snapshot(ActorRef<MapSnapshotter::Callback>); @@ -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<bool, std::string> 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 <mbgl/test/util.hpp> + +#include <mbgl/map/camera.hpp> +#include <mbgl/map/map_snapshotter.hpp> +#include <mbgl/storage/resource_options.hpp> +#include <mbgl/util/constants.hpp> + +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", |