Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More context #2537

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions platform/android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ MapLibre welcomes participation and contributions from everyone. Please read [`C

### ✨ Features and improvements

## 10.3.2-pre3

- Additional symbol instance checks building on previous success in detecting corruption and avoiding crashes
- More context from check calls to help narrow down the origin of corruption

Note: CI checks are not maintained for backporting releases, so only manual testing is done.

## 10.3.2-pre2

A minor fix for a bug introduced in 10.3.2-pre1 which caused symbols to disappear randomly.
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/layout/symbol_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ optional<size_t> SymbolInstance::getDefaultHorizontalPlacedTextIndex() const {
}

bool SymbolInstance::check(std::size_t v, int n, std::string_view source) const {
if (!isFailed && v != checkVal) {
if (v != checkVal) {
isFailed = true;
Log::Error(Event::Crash, "SymbolInstance corrupted at " + util::toString(n) + " with value " + util::toString(v) + " from '" + std::string(source) + "'");
}
return !isFailed;
}

bool SymbolInstance::checkKey() const {
if (!isFailed && key.size() > 1000) { // largest observed value=62
if (key.size() > 1000) { // largest observed value=62
isFailed = true;
Log::Error(Event::Crash, "SymbolInstance key corrupted with size=" + util::toString(key.size()));
}
Expand Down
147 changes: 77 additions & 70 deletions src/mbgl/layout/symbol_instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#include <mbgl/style/layers/symbol_layer_properties.hpp>
#include <mbgl/util/bitmask_operations.hpp>

#define STRINGIZE(x) STRINGIZE2(x)
#define STRINGIZE2(x) #x
#define __LINE_STRING__ STRINGIZE(__LINE__)
#define __SOURCE_LOCATION__ __FILE__ ":" __LINE_STRING__

namespace mbgl {

class Anchor;
Expand Down Expand Up @@ -85,37 +90,39 @@ class SymbolInstance {
const optional<SymbolQuads>& verticalIconQuads() const;
void releaseSharedData();

bool check(std::string_view source = std::string_view()) const {
return !isFailed &&
check(check01, 1, source) &&
check(check02, 2, source) &&
check(check03, 3, source) &&
check(check04, 4, source) &&
check(check05, 5, source) &&
check(check06, 6, source) &&
check(check07, 7, source) &&
check(check08, 8, source) &&
check(check09, 9, source) &&
check(check10, 10, source) &&
check(check11, 11, source) &&
check(check12, 12, source) &&
check(check13, 13, source) &&
check(check14, 14, source) &&
check(check15, 15, source) &&
check(check16, 16, source) &&
check(check17, 17, source) &&
check(check18, 18, source) &&
check(check19, 19, source) &&
check(check20, 20, source) &&
check(check21, 21, source) &&
check(check22, 22, source) &&
check(check23, 23, source) &&
check(check24, 24, source) &&
check(check25, 25, source) &&
check(check26, 26, source) &&
check(check27, 27, source) &&
check(check28, 28, source) &&
check(check29, 29, source);
bool check(std::string_view source) const {
if (isFailed)
return false;
check(check01, 1, source);
check(check02, 2, source);
check(check03, 3, source);
check(check04, 4, source);
check(check05, 5, source);
check(check06, 6, source);
check(check07, 7, source);
check(check08, 8, source);
check(check09, 9, source);
check(check10, 10, source);
check(check11, 11, source);
check(check12, 12, source);
check(check13, 13, source);
check(check14, 14, source);
check(check15, 15, source);
check(check16, 16, source);
check(check17, 17, source);
check(check18, 18, source);
check(check19, 19, source);
check(check20, 20, source);
check(check21, 21, source);
check(check22, 22, source);
check(check23, 23, source);
check(check24, 24, source);
check(check25, 25, source);
check(check26, 26, source);
check(check27, 27, source);
check(check28, 28, source);
check(check29, 29, source);
return !isFailed;
}
bool checkIndex(const optional<std::size_t>& index, std::size_t size, std::string_view source) const;
bool checkIndexes(std::size_t textCount, std::size_t iconSize, std::size_t sdfSize, std::string_view source) const {
Expand All @@ -128,45 +135,45 @@ class SymbolInstance {
checkIndex(placedVerticalIconIndex, hasSdfIcon() ? sdfSize : iconSize, source);
}

const Anchor& getAnchor() const { check(); return anchor; }
std::size_t getRightJustifiedGlyphQuadsSize() const { check(); return rightJustifiedGlyphQuadsSize; }
std::size_t getCenterJustifiedGlyphQuadsSize() const { check(); return centerJustifiedGlyphQuadsSize; }
std::size_t getLeftJustifiedGlyphQuadsSize() const { check(); return leftJustifiedGlyphQuadsSize; }
std::size_t getVerticalGlyphQuadsSize() const { check(); return verticalGlyphQuadsSize; }
std::size_t getIconQuadsSize() const { check(); return iconQuadsSize; }
const CollisionFeature& getTextCollisionFeature() const { check(); return textCollisionFeature; }
const CollisionFeature& getIconCollisionFeature() const { check(); return iconCollisionFeature; }
const optional<CollisionFeature>& getVerticalTextCollisionFeature() const { check(); return verticalTextCollisionFeature; }
const optional<CollisionFeature>& getVerticalIconCollisionFeature() const { check(); return verticalIconCollisionFeature; }
WritingModeType getWritingModes() const { check(); return writingModes; }
std::size_t getLayoutFeatureIndex() const { check(); return layoutFeatureIndex; }
std::size_t getDataFeatureIndex() const { check(); return dataFeatureIndex; }
std::array<float, 2> getTextOffset() const { check(); return textOffset; }
std::array<float, 2> getIconOffset() const { check(); return iconOffset; }
const std::u16string& getKey() const { check(); checkKey(); return key; }
optional<size_t> getPlacedRightTextIndex() const { check(); return placedRightTextIndex; }
optional<size_t> getPlacedCenterTextIndex() const { check(); return placedCenterTextIndex; }
optional<size_t> getPlacedLeftTextIndex() const { check(); return placedLeftTextIndex; }
optional<size_t> getPlacedVerticalTextIndex() const { check(); return placedVerticalTextIndex; }
optional<size_t> getPlacedIconIndex() const { check(); return placedIconIndex; }
optional<size_t> getPlacedVerticalIconIndex() const { check(); return placedVerticalIconIndex; }
float getTextBoxScale() const { check(); return textBoxScale; }
std::array<float, 2> getVariableTextOffset() const { check(); return variableTextOffset; }
bool getSingleLine() const { check(); return singleLine; }

uint32_t getCrossTileID() const { check(); return crossTileID; }
void setCrossTileID(uint32_t x) { check(); crossTileID = x; check(); }

optional<size_t>& refPlacedRightTextIndex() { check(); return placedRightTextIndex; }
optional<size_t>& refPlacedCenterTextIndex() { check(); return placedCenterTextIndex; }
optional<size_t>& refPlacedLeftTextIndex() { check(); return placedLeftTextIndex; }
optional<size_t>& refPlacedVerticalTextIndex() { check(); return placedVerticalTextIndex; }
optional<size_t>& refPlacedIconIndex() { check(); return placedIconIndex; }
optional<size_t>& refPlacedVerticalIconIndex() { check(); return placedVerticalIconIndex; }

void setPlacedRightTextIndex(optional<size_t> x) { check(); placedRightTextIndex = x; check(); }
void setPlacedCenterTextIndex(optional<size_t> x) { check(); placedCenterTextIndex = x; check(); }
void setPlacedLeftTextIndex(optional<size_t> x) { check(); placedLeftTextIndex = x; check(); }
const Anchor& getAnchor(std::string_view source) const { check(source); return anchor; }
std::size_t getRightJustifiedGlyphQuadsSize(std::string_view source) const { check(source); return rightJustifiedGlyphQuadsSize; }
std::size_t getCenterJustifiedGlyphQuadsSize(std::string_view source) const { check(source); return centerJustifiedGlyphQuadsSize; }
std::size_t getLeftJustifiedGlyphQuadsSize(std::string_view source) const { check(source); return leftJustifiedGlyphQuadsSize; }
std::size_t getVerticalGlyphQuadsSize(std::string_view source) const { check(source); return verticalGlyphQuadsSize; }
std::size_t getIconQuadsSize(std::string_view source) const { check(source); return iconQuadsSize; }
const CollisionFeature& getTextCollisionFeature(std::string_view source) const { check(source); return textCollisionFeature; }
const CollisionFeature& getIconCollisionFeature(std::string_view source) const { check(source); return iconCollisionFeature; }
const optional<CollisionFeature>& getVerticalTextCollisionFeature(std::string_view source) const { check(source); return verticalTextCollisionFeature; }
const optional<CollisionFeature>& getVerticalIconCollisionFeature(std::string_view source) const { check(source); return verticalIconCollisionFeature; }
WritingModeType getWritingModes(std::string_view source) const { check(source); return writingModes; }
std::size_t getLayoutFeatureIndex(std::string_view source) const { check(source); return layoutFeatureIndex; }
std::size_t getDataFeatureIndex(std::string_view source) const { check(source); return dataFeatureIndex; }
std::array<float, 2> getTextOffset(std::string_view source) const { check(source); return textOffset; }
std::array<float, 2> getIconOffset(std::string_view source) const { check(source); return iconOffset; }
const std::u16string& getKey(std::string_view source) const { check(source); checkKey(); return key; }
optional<size_t> getPlacedRightTextIndex(std::string_view source) const { check(source); return placedRightTextIndex; }
optional<size_t> getPlacedCenterTextIndex(std::string_view source) const { check(source); return placedCenterTextIndex; }
optional<size_t> getPlacedLeftTextIndex(std::string_view source) const { check(source); return placedLeftTextIndex; }
optional<size_t> getPlacedVerticalTextIndex(std::string_view source) const { check(source); return placedVerticalTextIndex; }
optional<size_t> getPlacedIconIndex(std::string_view source) const { check(source); return placedIconIndex; }
optional<size_t> getPlacedVerticalIconIndex(std::string_view source) const { check(source); return placedVerticalIconIndex; }
float getTextBoxScale(std::string_view source) const { check(source); return textBoxScale; }
std::array<float, 2> getVariableTextOffset(std::string_view source) const { check(source); return variableTextOffset; }
bool getSingleLine(std::string_view source) const { check(source); return singleLine; }

uint32_t getCrossTileID(std::string_view source) const { check(source); return crossTileID; }
void setCrossTileID(uint32_t x, std::string_view source) { check(source); crossTileID = x; }

optional<size_t>& refPlacedRightTextIndex(std::string_view source) { check(source); return placedRightTextIndex; }
optional<size_t>& refPlacedCenterTextIndex(std::string_view source) { check(source); return placedCenterTextIndex; }
optional<size_t>& refPlacedLeftTextIndex(std::string_view source) { check(source); return placedLeftTextIndex; }
optional<size_t>& refPlacedVerticalTextIndex(std::string_view source) { check(source); return placedVerticalTextIndex; }
optional<size_t>& refPlacedIconIndex(std::string_view source) { check(source); return placedIconIndex; }
optional<size_t>& refPlacedVerticalIconIndex(std::string_view source) { check(source); return placedVerticalIconIndex; }

void setPlacedRightTextIndex(optional<size_t> x, std::string_view source) { check(source); placedRightTextIndex = x; }
void setPlacedCenterTextIndex(optional<size_t> x, std::string_view source) { check(source); placedCenterTextIndex = x; }
void setPlacedLeftTextIndex(optional<size_t> x, std::string_view source) { check(source); placedLeftTextIndex = x; }

static constexpr uint32_t invalidCrossTileID() { return std::numeric_limits<uint32_t>::max(); }

Expand Down
Loading
Loading