From a4f3887a0e806d823ddb1a719cbf0ec00299ba21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Wed, 9 Nov 2016 16:53:10 +0100 Subject: [PATCH 1/2] [core] don't initialize with Duration::min() to avoid arithmetic overflows In FrameHistory::needsAnimation, we are computing "time - previousTime", but since previousTime was initialized to Duration::min(), we got a integer overflow, which produced invalid values. --- src/mbgl/renderer/frame_history.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mbgl/renderer/frame_history.hpp b/src/mbgl/renderer/frame_history.hpp index d8fd06d27b3..dfa27510389 100644 --- a/src/mbgl/renderer/frame_history.hpp +++ b/src/mbgl/renderer/frame_history.hpp @@ -29,8 +29,8 @@ class FrameHistory { const AlphaImage opacities{ { 256, 1 } }; int16_t previousZoomIndex = 0; - TimePoint previousTime = TimePoint::min(); - TimePoint time = TimePoint::min(); + TimePoint previousTime; + TimePoint time; bool firstFrame = true; bool dirty = true; From 3eb4bc11d02550cb8396f25caf99e6882896ee17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Wed, 9 Nov 2016 17:00:52 +0100 Subject: [PATCH 2/2] [core] add continuous rendering test that terminates once it settles down This is to test that continuous mode stops rerendering once no further changes are needed, i.e. to test the absence of "busy rendering". --- test/map/map.test.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index a62bd10b57b..71267e9a602 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -442,3 +443,61 @@ TEST(Map, DontLoadUnneededTiles) { EXPECT_EQ(referenceTiles[z], tiles) << "zoom level " << z; } } + + +class MockBackend : public HeadlessBackend { +public: + std::function callback; + void invalidate() override { + if (callback) { + callback(); + } + } +}; + +TEST(Map, ContinuousRendering) { + util::RunLoop runLoop; + MockBackend backend; + OffscreenView view { backend.getContext() }; + ThreadPool threadPool { 4 }; + +#ifdef MBGL_ASSET_ZIP + // Regenerate with `cd test/fixtures/api/ && zip -r assets.zip assets/` + DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets.zip"); +#else + DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets"); +#endif + + Map map(backend, view.size, 1, fileSource, threadPool, MapMode::Continuous); + + using namespace std::chrono_literals; + + util::Timer emergencyShutoff; + emergencyShutoff.start(10s, 0s, [&] { + util::RunLoop::Get()->stop(); + FAIL() << "Did not stop rendering"; + }); + + util::Timer timer; + util::AsyncTask render{[&] { + if (map.isFullyLoaded()) { + // Abort the test after 1 second after the map loading fully. Note that a "fully loaded + // map" doesn't mean that we won't render anymore: we could still render fade in/fade + // out or other animations. + // If we are continuing to render indefinitely, the emergency shutoff above will trigger + // and the test will fail since the regular time will be constantly reset. + timer.start(1s, 0s, [&] { + util::RunLoop::Get()->stop(); + }); + } + + map.render(view); + }}; + + backend.callback = [&] { + render.send(); + }; + + map.setStyleJSON(util::read_file("test/fixtures/api/water.json")); + util::RunLoop::Get()->run(); +}