diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index ef3f34f59..c5afb3843 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -176,7 +176,7 @@ void RenderTileSetSource::update(Immutable baseImpl_, tilePyramid.clearAll(); } - if (!implTileset) return; + if (!cachedTileset) return; updateInternal(*cachedTileset, layers, needsRendering, needsRelayout, parameters); } diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp index 09c433b6a..ca0e79f46 100644 --- a/test/style/source.test.cpp +++ b/test/style/source.test.cpp @@ -42,6 +42,7 @@ #include #include +#include using namespace mbgl; using SourceType = mbgl::style::SourceType; @@ -793,3 +794,41 @@ TEST(Source, CustomGeometrySourceSetTileData) { test.run(); } +TEST(Source, RenderTileSetSourceUpdate) { + SourceTest test; + + class FakeRenderTileSetSource : public RenderTileSetSource { + public: + explicit FakeRenderTileSetSource(Immutable impl_) + : RenderTileSetSource(std::move(impl_)) {} + + MOCK_METHOD0(mockedUpdateInternal, void()); + + void updateInternal(const Tileset&, + const std::vector>&, + const bool, const bool, const TileParameters&) override { + mockedUpdateInternal(); + } + + const optional& getTileset() const override { + return static_cast(*baseImpl).tileset; + } + }; + + VectorSource initialized("source", Tileset{ {"tiles"} }); + initialized.loadDescription(*test.fileSource); + + FakeRenderTileSetSource renderTilesetSource { initialized.baseImpl }; + + LineLayer layer("id", "source"); + Immutable layerProperties = makeMutable(staticImmutableCast(layer.baseImpl)); + std::vector> layers { layerProperties }; + + // Check that `updateInternal()` is called even if the updated source has not yet loaded description. + EXPECT_CALL(renderTilesetSource, mockedUpdateInternal()).Times(2); + RenderSource* renderSource = &renderTilesetSource; + renderSource->update(initialized.baseImpl, layers, true, true, test.tileParameters); + + VectorSource uninitialized("source", "http://url"); + renderSource->update(uninitialized.baseImpl, layers, true, true, test.tileParameters); +}