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

Commit

Permalink
[core] Check if pattern dependencies or pattern positions are missing
Browse files Browse the repository at this point in the history
Add check for optional pattern dependencies and don't bind empty vertex
buffers if pattern positions are missing.
  • Loading branch information
alexshalamov committed May 20, 2019
1 parent 9fe5256 commit 521ac5c
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/mbgl/renderer/paint_property_binder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class CompositeCrossFadedPaintPropertyBinder final : public PaintPropertyBinder<

void populateVertexVector(const GeometryTileFeature&, std::size_t length, const ImagePositions& patternPositions, const optional<PatternDependency>& patternDependencies, const style::expression::Value&) override {

if (patternDependencies->mid.empty()) {
if (!patternDependencies || patternDependencies->mid.empty()) {
// Unlike other propperties with expressions that evaluate to null, the default value for `*-pattern` properties is an empty
// string and will not have a valid entry in patternPositions. We still need to populate the attribute buffers to avoid crashes
// when we try to draw the layer because we don't know at draw time if all features were evaluated to valid pattern dependencies.
Expand Down Expand Up @@ -354,19 +354,29 @@ class CompositeCrossFadedPaintPropertyBinder final : public PaintPropertyBinder<
}

void upload(gfx::UploadPass& uploadPass) override {
patternToVertexBuffer = uploadPass.createVertexBuffer(std::move(patternToVertexVector));
zoomInVertexBuffer = uploadPass.createVertexBuffer(std::move(zoomInVertexVector));
zoomOutVertexBuffer = uploadPass.createVertexBuffer(std::move(zoomOutVertexVector));
if (!patternToVertexVector.empty()) {
assert(!zoomInVertexVector.empty());
assert(!zoomOutVertexVector.empty());
patternToVertexBuffer = uploadPass.createVertexBuffer(std::move(patternToVertexVector));
zoomInVertexBuffer = uploadPass.createVertexBuffer(std::move(zoomInVertexVector));
zoomOutVertexBuffer = uploadPass.createVertexBuffer(std::move(zoomOutVertexVector));
}
}

std::tuple<optional<gfx::AttributeBinding>, optional<gfx::AttributeBinding>> attributeBinding(const PossiblyEvaluatedPropertyValue<Faded<T>>& currentValue) const override {
if (currentValue.isConstant()) {
return {};
} else {
return std::tuple<optional<gfx::AttributeBinding>, optional<gfx::AttributeBinding>>{
gfx::attributeBinding(*patternToVertexBuffer),
gfx::attributeBinding(crossfade.fromScale == 2 ? *zoomInVertexBuffer : *zoomOutVertexBuffer)
};
if (patternToVertexBuffer) {
assert(zoomInVertexBuffer);
assert(zoomOutVertexBuffer);
return std::tuple<optional<gfx::AttributeBinding>, optional<gfx::AttributeBinding>>{
gfx::attributeBinding(*patternToVertexBuffer),
gfx::attributeBinding(crossfade.fromScale == 2 ? *zoomInVertexBuffer : *zoomOutVertexBuffer)
};
}

return std::tuple<optional<gfx::AttributeBinding>, optional<gfx::AttributeBinding>>{{}, {}};
}
}

Expand Down

0 comments on commit 521ac5c

Please sign in to comment.