[Bug] Tile3DLayer selects no tiles until the camera moves when tileset.json loads right after a layer update

Open Beginner friendly
#11,365 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@lee3Q is already working on this.

Since Nov 28, 2026.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active

Research direction

Start in modules/geo-layers/src/tile-3d-layer/tile-3d-layer.ts with activateViewport, updateState, _updateTileset and _loadTileset, and compare _loadTileset with _onTileLoad, which already falls back to lastUpdatedViewports. Run the repro page in the issue with a local server to confirm tiles stay at zero until the camera moves. Done when _loadTileset selects tiles for the last seen viewports and the repro's tilesWithCameraStill count is non-zero across the delay sweep.

Written by the indexing model from the issue text.

Description

Description

TL;DR: if tileset.json finishes loading after a layer update has consumed state.activeViewports and before
the next draw refills it, _loadTileset selects tiles for an empty set of viewports. Later draws with the same
camera count as unchanged, so the layer never selects tiles until the camera moves. _onTileLoad already
selects with lastUpdatedViewports; _loadTileset should fall back to it too.

How it happens (line numbers from master at
978c534):

  1. The first draw calls activateViewport. With no lastUpdatedViewports it stores the viewport in
    activeViewports and sets viewportChanged
    (L192-L202).
  2. The next updateState calls _updateTileset(activeViewports), which returns early because tileset3d is
    still null, then moves the viewports to lastUpdatedViewports and empties activeViewports
    (L160-L168).
  3. tileset.json finishes before the next draw. _loadTileset calls _updateTileset(this.state.activeViewports)
    with the empty object, so nothing is selected
    (L280).
  4. Every later draw with the same camera finds viewport.equals(lastViewport), so viewportChanged is never set
    again and updateState never selects. Tiles appear only when the camera moves.

In a plain Deck the update and the draw run back to back in one frame, so nothing can land between steps 2
and 3. With MapLibreOverlay in interleaved mode, the layer update and MapLibre's draw run in separate
callbacks, and an app that calls setProps({layers}) on every frame (any animation) runs the update in its
own callback. A tileset.json that finishes in between hits the bug.

We hit it in an app with an interleaved MapLibreOverlay, a TripsLayer animated by setProps every frame, and
a Tile3DLayer that is created when the camera jumps in to a zoom where buildings show. After the jump,
downtown had no buildings until the user started to orbit, and then all of the tile content (70 large
textures) uploaded in the same second, with frames of 150 to 330 ms. An event log on the layer showed the
order above: activateViewport with no last viewport, one _updateTileset with the viewport, then
_updateTileset({}) from _loadTileset, then only "same viewport" activations until the camera moved.

Flavors

Script tag, MapboxOverlay (the repro and our app use MapLibreOverlay from @deck.gl/maplibre, interleaved).

Expected Behavior

When tileset.json loads, the layer selects tiles for the camera it has already seen, whatever the order of
updates and draws, as _onTileLoad does.

Steps to Reproduce

Standalone page (deck.gl 9.4.2, loaders.gl 4.5.5, MapLibre 6.19.0, Cesium's BatchedColors test tileset
from the loaders.gl repo). Save it as an .html file and open it through any local web server.

tile3d-race-maplibre.html
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Tile3DLayer in an interleaved MapLibre overlay: no tiles until the camera moves</title>
  <script src="https://unpkg.com/[email protected]/dist.min.js"></script>
  <script src="https://unpkg.com/@loaders.gl/[email protected]/dist/dist.min.js"></script>
  <link href="https://unpkg.com/[email protected]/dist/maplibre-gl.css" rel="stylesheet">
  <style>
    body { margin: 0; font: 14px system-ui, sans-serif; }
    #map { position: absolute; inset: 0; }
    #status { position: absolute; top: 8px; left: 8px; z-index: 1; background: #fff; padding: 6px 10px; white-space: pre; }
  </style>
</head>
<body>
  <div id="map"></div>
  <div id="status">loading</div>
  <script type="module">
    // A Tile3DLayer added to an interleaved MapLibre overlay while the camera stands still.
    // The page sets the layers on every animation frame, as animated apps do. Each trial adds a new layer,
    // holds its tileset.json back for `delay` ms, then counts tile loads.
    // Expected: 1 tile loads in every trial. Bug: some trials load nothing until the camera moves.
    // ?patched=1 applies the proposed change to Tile3DLayer._loadTileset.
    import * as maplibre from 'https://unpkg.com/[email protected]/dist/maplibre-gl.mjs';
    const maplibregl = maplibre.default ?? maplibre;
    const TILESET = 'https://raw.githubusercontent.com/visgl/loaders.gl/a4e619a86770926ea05a26f0aeeb648c0eb1e3c0/modules/tiles-3d/test/3d-tiles/data/CesiumJS/Batched/BatchedColors/tileset.json';
    const {MapLibreOverlay, Tile3DLayer} = deck;
    const {Tiles3DLoader} = loaders;

    if (new URLSearchParams(location.search).has('patched')) {
      const loadTileset = Tile3DLayer.prototype._loadTileset;
      Tile3DLayer.prototype._loadTileset = async function (url) {
        await loadTileset.call(this, url);
        const {activeViewports, lastUpdatedViewports} = this.state;
        this._updateTileset(Object.keys(activeViewports).length ? activeViewports : lastUpdatedViewports);
      };
    }

    // tileset.json waits for the current trial's gate; its body is fetched once up front.
    const realFetch = window.fetch.bind(window);
    const body = await realFetch(TILESET).then(r => r.text());
    let gate = Promise.resolve();
    window.fetch = async (input, init) => {
      const url = typeof input === 'string' ? input : input.url;
      if (url !== TILESET) return realFetch(input, init);
      await gate;
      const response = new Response(body, {headers: {'content-type': 'application/json'}});
      Object.defineProperty(response, 'url', {value: TILESET});
      return response;
    };

    const map = new maplibregl.Map({
      container: 'map',
      style: {version: 8, sources: {}, layers: [{id: 'bg', type: 'background', paint: {'background-color': '#dde'}}]},
      center: [-75.61209, 40.04253], zoom: 18, pitch: 45
    });
    const overlay = new MapLibreOverlay({interleaved: true, layers: []});
    map.addControl(overlay);
    await new Promise(resolve => map.once('load', resolve));

    const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
    const status = document.getElementById('status');
    // Like an animated app: new layer instances with the same props on every frame.
    let current = null;
    const makeLayer = () => current && new Tile3DLayer(current);
    const frame = () => {
      requestAnimationFrame(frame);
      overlay.setProps({layers: current ? [makeLayer()] : []});
    };
    requestAnimationFrame(frame);

    window.runTrial = async (n, delay) => {
      let loads = 0, release;
      gate = new Promise(resolve => { release = resolve; });
      current = {id: `tiles-${n}`, data: TILESET, loader: Tiles3DLoader, onTileLoad: () => { loads++; }};
      setTimeout(release, delay);
      await sleep(2000);
      const stillCamera = loads;
      map.jumpTo({bearing: map.getBearing() + 1});
      await sleep(1000);
      current = null;
      await sleep(300);
      return {delay, tilesWithCameraStill: stillCamera, tilesAfterCameraMove: loads};
    };
    window.ready = true;
    status.textContent = 'ready';
  </script>
</body>
</html>

To run trials from the console once the page says ready:

for (let i = 0; i < 30; i++) console.log(await runTrial(i, i * 2));

The page sets its layers on every animation frame, like an animated app. Each trial adds a new Tile3DLayer
with the camera still, holds tileset.json back for a given delay, counts tile loads after 2 s, then moves
the camera by one degree and counts again. window.runTrial(n, delayMs) runs one trial.

Result in Chrome, 40 trials with delays of 0 to 78 ms in 2 ms steps: 10 of 40 loaded no tile with the camera
still (every delay from 22 to 38 ms, and 42 ms), and each of those loaded its tile as soon as the camera moved.
With ?patched=1 (the change below): 0 of 40. The machine was heavily loaded during the run, so the failing
delays will shift on other hardware; a sweep around 10 to 60 ms should find them.

Because it is a race, a trial does not fail every time. The page exists to show the failure with public data;
the code path above is the deterministic part.

Suggested fix

In _loadTileset, select with the viewports the layer has already handled when no new ones are waiting:

const {activeViewports, lastUpdatedViewports} = this.state;
this._updateTileset(Object.keys(activeViewports).length ? activeViewports : lastUpdatedViewports);

Our workaround until then, a subclass that treats every view as new until a first selection has run with the
tileset loaded:

class BuildingTilesLayer extends Tile3DLayer {
  static layerName = 'BuildingTilesLayer';
  activateViewport(viewport: Viewport) {
    if (this.state.tileset3d && this.state.frameNumber === undefined) this.state.lastUpdatedViewports = null;
    super.activateViewport(viewport);
  }
}

Possibly related: #9585 (layer added after the map loaded with a still camera, model not shown; closed without
a repro).

Environment
  • Framework version: deck.gl 9.4.2 (the same code is on master at 978c534)
  • Browser: Chrome 158
  • OS: macOS 26
Logs

No errors or warnings. The tileset loads (onTilesetLoad fires) but no tile content loads until the camera moves.

Dominant language
TypeScript
Stars
14.8k
Forks
2.3k
Avg merge
1d 9h
Merged PRs (30d)
230

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from visgl/deck.gl

All issues in visgl/deck.gl

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.