From 57c34747a24bc2c3e5b27e17c1991d6b9a4aa68c Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Tue, 16 Jun 2015 13:08:38 +0300 Subject: [PATCH] Report errors for renderStill() misuse using the callback Use the callback provided for reporting the errors instead of throwing an exception. The problem with the exception is it will happen on the Map thread which makes it impossible to the user of our API to catch, ultimately resulting in a crash. In the scenario of not providing a callback, we just print an error. --- src/mbgl/map/map_context.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index bd288a5cd..7f8323137 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -279,12 +279,24 @@ void MapContext::update() { } void MapContext::renderStill(StillImageCallback fn) { + if (!fn) { + Log::Error(Event::General, "StillImageCallback not set"); + return; + } + if (data.mode != MapMode::Still) { - throw util::Exception("Map is not in still image render mode"); + fn(std::make_exception_ptr(util::MisuseException("Map is not in still image render mode")), nullptr); + return; } if (callback) { - throw util::Exception("Map is currently rendering an image"); + fn(std::make_exception_ptr(util::MisuseException("Map is currently rendering an image")), nullptr); + return; + } + + if (!style) { + fn(std::make_exception_ptr(util::MisuseException("Map doesn't have a style")), nullptr); + return; } if (style->getLastError()) {