Report errors when parsing raster tiles

Use the same API/pattern for parsing raster tiles as we use for vector
tiles. Forward the error as an exception that will ultimately reach the
StillImageCallback.

Also set the tile to State::obsolete on error like we do for vector
tiles.
This commit is contained in:
Thiago Marcos P. Santos
2015-07-02 16:04:30 +03:00
parent c357ce540a
commit 9cc986e758
8 changed files with 26 additions and 18 deletions

View File

@@ -44,15 +44,18 @@ void RasterTileData::request(float pixelRatio,
state = State::loaded;
workRequest = worker.parseRasterTile(bucket, res.data, [this, callback] (bool result) {
workRequest = worker.parseRasterTile(bucket, res.data, [this, callback] (TileParseResult result) {
if (state != State::loaded) {
return;
}
if (result) {
state = State::parsed;
if (result.is<State>()) {
state = result.get<State>();
} else {
state = State::invalid;
std::stringstream message;
message << "Failed to parse [" << std::string(id) << "]: " << result.get<std::string>();
error = message.str();
state = State::obsolete;
}
callback();

View File

@@ -28,9 +28,6 @@ public:
// the TileData object is not effectively on the 'invalid' state and will
// cause tiles on 'invalid' state to get reloaded.
//
// Raster tiles (only) are changing to 'invalid' on error, which will cause a
// re-request of the tile.
//
// loading:
// A request to the FileSource was made for the actual tile data and TileData
// is waiting for it to arrive.

View File

@@ -23,8 +23,8 @@ void RasterBucket::render(Painter& painter,
painter.renderRaster(*this, layer_desc, id, matrix);
}
bool RasterBucket::setImage(const std::string &data) {
return raster.load(data);
bool RasterBucket::setImage(std::unique_ptr<util::Image> image) {
return raster.load(std::move(image));
}
void RasterBucket::drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array) {

View File

@@ -20,7 +20,7 @@ public:
void render(Painter&, const StyleLayer&, const TileID&, const mat4&) override;
bool hasData() const;
bool setImage(const std::string &data);
bool setImage(std::unique_ptr<util::Image> image);
const StyleLayoutRaster &layout;

View File

@@ -25,8 +25,8 @@ bool Raster::isLoaded() const {
return loaded;
}
bool Raster::load(const std::string &data) {
img = std::make_unique<util::Image>(data);
bool Raster::load(std::unique_ptr<util::Image> image) {
img = std::move(image);
width = img->getWidth();
height = img->getHeight();

View File

@@ -6,7 +6,6 @@
#include <mbgl/util/ptr.hpp>
#include <mbgl/util/chrono.hpp>
#include <string>
#include <mutex>
typedef struct uv_loop_s uv_loop_t;
@@ -20,7 +19,7 @@ public:
~Raster();
// load image data
bool load(const std::string &img);
bool load(std::unique_ptr<util::Image> image);
// bind current texture
void bind(bool linear = false);

View File

@@ -20,8 +20,17 @@ public:
util::ThreadContext::setFileSource(fs);
}
void parseRasterTile(RasterBucket* bucket, std::string data, std::function<void (bool)> callback) {
callback(bucket->setImage(data));
void parseRasterTile(RasterBucket* bucket, std::string data, std::function<void (TileParseResult)> callback) {
std::unique_ptr<util::Image> image(new util::Image(data));
if (!(*image)) {
callback(TileParseResult("error parsing raster image"));
}
if (!bucket->setImage(std::move(image))) {
callback(TileParseResult("error setting raster image to bucket"));
}
callback(TileParseResult(TileData::State::parsed));
}
void parseVectorTile(TileWorker* worker, std::string data, std::function<void (TileParseResult)> callback) {
@@ -56,7 +65,7 @@ Worker::Worker(std::size_t count) {
Worker::~Worker() = default;
std::unique_ptr<WorkRequest> Worker::parseRasterTile(RasterBucket& bucket, std::string data, std::function<void (bool)> callback) {
std::unique_ptr<WorkRequest> Worker::parseRasterTile(RasterBucket& bucket, std::string data, std::function<void (TileParseResult)> callback) {
current = (current + 1) % threads.size();
return threads[current]->invokeWithCallback(&Worker::Impl::parseRasterTile, callback, &bucket, data);
}

View File

@@ -34,7 +34,7 @@ public:
Request parseRasterTile(
RasterBucket&,
std::string data,
std::function<void (bool)> callback);
std::function<void (TileParseResult)> callback);
Request parseVectorTile(
TileWorker&,