Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
lock the StyleBucket to avoid crashing
Browse files Browse the repository at this point in the history
stopgap until we have a solution that doesn't mutate the style objects while parsing a tile
  • Loading branch information
kkaefer committed Feb 11, 2015
1 parent 8258f51 commit c452b21
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/mbgl/map/tile_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,14 @@ void TileParser::applyLayoutProperty(PropertyKey key, ClassProperties &classProp

template <>
void TileParser::applyLayoutProperties<FillProperties>(StyleBucket &bucket_desc, const float) {
auto lock = bucket_desc.lock();
bucket_desc.render.set<StyleBucketFill>();
// no-op; Fill buckets don't currently have any applicable layout properties
}

template<>
void TileParser::applyLayoutProperties<LineProperties>(StyleBucket &bucket_desc, const float z) {
auto lock = bucket_desc.lock();
bucket_desc.render.set<StyleBucketLine>();
StyleBucketLine &line = bucket_desc.render.get<StyleBucketLine>();
applyLayoutProperty(PropertyKey::LineCap, bucket_desc.layout, line.cap, z);
Expand All @@ -142,6 +144,7 @@ void TileParser::applyLayoutProperties<LineProperties>(StyleBucket &bucket_desc,

template<>
void TileParser::applyLayoutProperties<SymbolProperties>(StyleBucket &bucket_desc, const float z) {
auto lock = bucket_desc.lock();
bucket_desc.render.set<StyleBucketSymbol>();
StyleBucketSymbol &symbol = bucket_desc.render.get<StyleBucketSymbol>();
applyLayoutProperty(PropertyKey::SymbolPlacement, bucket_desc.layout, symbol.placement, z);
Expand Down
8 changes: 7 additions & 1 deletion src/mbgl/style/style_bucket.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <mbgl/style/style_bucket.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/util/uv_detail.hpp>

namespace mbgl {

Expand All @@ -8,7 +10,7 @@ template<> const StyleBucketSymbol &defaultLayoutProperties() { static StyleBuck
template<> const StyleBucketRaster &defaultLayoutProperties() { static StyleBucketRaster p; return p; }
template<> const StyleBucketBackground &defaultLayoutProperties() { static StyleBucketBackground p; return p; }

StyleBucket::StyleBucket(StyleLayerType type_) : type(type_) {
StyleBucket::StyleBucket(StyleLayerType type_) : type(type_), mtx(util::make_unique<uv::mutex>()) {
switch (type) {
case StyleLayerType::Fill: render.set<StyleBucketFill>(); break;
case StyleLayerType::Line: render.set<StyleBucketLine>(); break;
Expand All @@ -18,4 +20,8 @@ StyleBucket::StyleBucket(StyleLayerType type_) : type(type_) {
}
}

uv::lock StyleBucket::lock() {
return uv::lock(mtx);
}

}
7 changes: 7 additions & 0 deletions src/mbgl/style/style_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <mbgl/util/variant.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/ptr.hpp>
#include <mbgl/util/uv.hpp>
#include <mbgl/style/class_properties.hpp>

#include <forward_list>
Expand Down Expand Up @@ -123,6 +124,12 @@ class StyleBucket : public util::noncopyable {
float min_zoom = -std::numeric_limits<float>::infinity();
float max_zoom = std::numeric_limits<float>::infinity();
VisibilityType visibility = VisibilityType::Visible;

public:
uv::lock lock();

private:
std::unique_ptr<uv::mutex> mtx;
};

template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/style/style_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <mbgl/style/style_layer_group.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/util/uv_detail.hpp>
#include <mbgl/platform/log.hpp>
#include <csscolorparser/csscolorparser.hpp>

Expand Down Expand Up @@ -318,7 +319,6 @@ template <> inline float defaultBaseValue<Color>() { return 1.0; }

template <typename T>
std::tuple<bool, Function<T>> StyleParser::parseFunction(JSVal value, const char *property_name) {

if (!value.IsObject()) {
return std::tuple<bool, Function<T>> { true, ConstantFunction<T>(std::get<1>(parseProperty<T>(value, property_name))) };
}
Expand Down

0 comments on commit c452b21

Please sign in to comment.