From 5475f3138bea139dd86a75ddd774051889a398c7 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 30 Apr 2015 14:48:04 -0400 Subject: [PATCH] Fix potential crash The promise could be deallocated before promise.set_value() had returned, which apparently caused an invalid read on some implementations. By moving the promise declaration up the stack, we ensure that the map is deallocated first, and therefore the map thread is joined, before the promise is deallocated. --- test/headless/headless.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/headless/headless.cpp b/test/headless/headless.cpp index 5a7674377..38fbf63b5 100644 --- a/test/headless/headless.cpp +++ b/test/headless/headless.cpp @@ -142,6 +142,8 @@ TEST_P(HeadlessTest, render) { } } + std::promise promise; + HeadlessView view(display, width, height, pixelRatio); DefaultFileSource fileSource(nullptr); Map map(view, fileSource, MapMode::Still); @@ -152,8 +154,6 @@ TEST_P(HeadlessTest, render) { map.setLatLngZoom(mbgl::LatLng(latitude, longitude), zoom); map.setBearing(bearing); - std::promise promise; - map.renderStill([&](std::unique_ptr image) { const std::string png = util::compress_png(image->width, image->height, image->pixels.get()); util::write_file("test/suite/tests/" + base + "/" + name + "/actual.png", png);