Skip to content

Map stays blank after WebGL context restore with standard-satellite (Object.keys(undefined) in ModelManager.reloadModels) #13760

Backlog

Description

@RobinNorrlander

mapbox-gl-js version

3.36.0 (also 3.18.0)

Browser and version

Chromium 151 (headless, SwiftShader); seen in production on iOS Safari, iOS in-app browsers and Android Chrome

Expected behavior

After webglcontextlost followed by webglcontextrestored, the map redraws, as it does with mapbox://styles/mapbox/standard or mapbox://styles/mapbox/satellite-streets-v12.

Actual behavior

With mapbox://styles/mapbox/standard-satellite, restoring the context throws TypeError: Cannot convert undefined or null to object and the map stays blank.

Map._contextRestored calls style.reloadModels(), which calls modelManager.reloadModels(scope) for every fragment style. For the imported basemap scope, modelManager.modelUris["basemap"] is never created because that style has no models, so load(undefined, ...) runs Object.keys(undefined). The throw skips the rest of _contextRestored (style.clearSources(), _update()), so nothing is redrawn.

A one-line fix in 3d-style/render/model_manager.ts:

reloadModels(scope: string) {
    this.load(this.modelUris[scope] || {}, scope, {forceReload: true});
}

We verified that this makes the map redraw after restore.

Link to the demonstration

None (needs an access token). Minimal page:

<div id="map" style="height:100vh"></div>
<script>
mapboxgl.accessToken = "<token>";
const map = new mapboxgl.Map({container: "map", style: "mapbox://styles/mapbox/standard-satellite"});
</script>

Steps to trigger the unexpected behavior

  1. Load the page above and wait for the map to load.
  2. In the console run:
    const ext = map.getCanvas().getContext("webgl2").getExtension("WEBGL_lose_context");
    ext.loseContext();
    setTimeout(() => ext.restoreContext(), 500);
  3. The error below is thrown and the map stays blank.

Relevant log output

TypeError: Cannot convert undefined or null to object
at Object.keys ()
at ModelManager.load (3d-style/render/model_manager.ts)
at ModelManager.reloadModels (3d-style/render/model_manager.ts)
at Style.reloadModels (src/style/style.ts)
at Map._contextRestored (src/ui/map.ts)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions