diff --git a/src/node_map.cpp b/src/node_map.cpp index e5b3fda5f..3ebed2e20 100644 --- a/src/node_map.cpp +++ b/src/node_map.cpp @@ -204,10 +204,15 @@ void NodeMap::startRender(std::unique_ptr options) { map.setLatLngZoom(mbgl::LatLng(options->latitude, options->longitude), options->zoom); map.setBearing(options->bearing); - map.renderStill([this](std::unique_ptr result) { - assert(!image); - image = std::move(result); - uv_async_send(async); + map.renderStill([this](const std::exception_ptr eptr, std::unique_ptr result) { + if (eptr) { + error = std::move(eptr); + uv_async_send(async); + } else { + assert(!image); + image = std::move(result); + uv_async_send(async); + } }); // Retain this object, otherwise it might get destructed before we are finished rendering the @@ -238,7 +243,16 @@ void NodeMap::renderFinished() { assert(!callback); assert(!image); - if (img) { + if (error) { + // This must be empty to be prepared for the next render call. + error = nullptr; + assert(!error); + + v8::Local argv[] = { + NanError("Error rendering image") + }; + cb->Call(1, argv); + } else if (img) { auto result = NanNew(); result->Set(NanNew("width"), NanNew(img->width)); result->Set(NanNew("height"), NanNew(img->height)); diff --git a/src/node_map.hpp b/src/node_map.hpp index 39784fef5..1cb32e40d 100644 --- a/src/node_map.hpp +++ b/src/node_map.hpp @@ -50,6 +50,7 @@ private: NodeFileSource &fs; mbgl::Map map; + std::exception_ptr error; std::unique_ptr image; std::unique_ptr callback; diff --git a/test/js/map.test.js b/test/js/map.test.js index 2d913b40a..de5126dc9 100644 --- a/test/js/map.test.js +++ b/test/js/map.test.js @@ -157,7 +157,6 @@ test('Map', function(t) { fileSource.request = function(req) { fs.readFile(path.join('test', req.url), function(err, data) { req.respond(err, { data: data }); - t.error(err); }); }; fileSource.cancel = function() {}; @@ -199,6 +198,17 @@ test('Map', function(t) { }); }); + t.test('returns an error', function(t) { + setup(fileSource, function(map) { + map.load(style); + map.render({ zoom: 1 }, function(err, data) { + t.ok(err); + t.equal(err.message, 'Error rendering image'); + t.end(); + }); + }); + }); + t.test('returns an image', function(t) { setup(fileSource, function(map) { map.load(style); diff --git a/vendor/mbgl b/vendor/mbgl index 9cd749b55..a20b89e4f 160000 --- a/vendor/mbgl +++ b/vendor/mbgl @@ -1 +1 @@ -Subproject commit 9cd749b55af8ca62f55726018189baeb856fa892 +Subproject commit a20b89e4ff991b650c7b09e203c2fee5c8e0c62b