[core] Initial state of Source::Impl::enabled must be true
Until Style::recalculate() is called to check that there are no visible layers using the source, we have to assume there are. Otherwise, Style::isLoaded() can return a false positive.
This commit is contained in:
@@ -74,7 +74,11 @@ public:
|
||||
const std::string id;
|
||||
|
||||
bool loaded = false;
|
||||
bool enabled = false;
|
||||
|
||||
// Tracks whether the source is used by any layers visible at the current zoom level. Must
|
||||
// be initialized to true so that Style::isLoaded() does not produce false positives if
|
||||
// called before Style::recalculate().
|
||||
bool enabled = true;
|
||||
|
||||
protected:
|
||||
void invalidateTiles();
|
||||
|
||||
@@ -305,7 +305,9 @@ bool Style::isLoaded() const {
|
||||
}
|
||||
|
||||
for (const auto& source: sources) {
|
||||
if (source->baseImpl->enabled && !source->baseImpl->isLoaded()) return false;
|
||||
if (source->baseImpl->enabled && !source->baseImpl->isLoaded()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!spriteStore->isLoaded()) {
|
||||
|
||||
@@ -17,6 +17,10 @@ TEST(Style, UnusedSource) {
|
||||
auto now = Clock::now();
|
||||
|
||||
style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
|
||||
|
||||
// If we haven't calculated whether the source is used, we have to assume it is used.
|
||||
EXPECT_FALSE(style.isLoaded());
|
||||
|
||||
style.cascade(now, MapMode::Still);
|
||||
style.recalculate(0, now, MapMode::Still);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user