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.
This commit is contained in:
John Firebaugh
2015-04-30 14:48:04 -04:00
parent b713930c7f
commit 5475f3138b

View File

@@ -142,6 +142,8 @@ TEST_P(HeadlessTest, render) {
}
}
std::promise<void> 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<void> promise;
map.renderStill([&](std::unique_ptr<const StillImage> 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);