Skip to content

fix(deck.gl-raster): stop leaking a WebGL vertex array per tile - #786

Merged
kylebarron merged 1 commit into
mainfrom
kyle/destroy-vertex-arrays
Oct 26, 2026
Merged

kylebarron merged 1 commit into
mainfrom
kyle/destroy-vertex-arrays

Conversation

@kylebarron

Copy link
Copy Markdown
Member

Note

This PR was written by Claude (Claude Code), not by @kylebarron.

@luma.gl/engine 9.4.2's Model.destroy() releases a model's pipeline, shaders, uniform store and geometry, but never destroys its vertex array. SimpleMeshLayer destroys its model when the layer is finalized and when it rebuilds the model, so every tile's MeshTextureLayer leaked one WebGL vertex array object for the life of the context. MeshTextureLayer now destroys the vertex array of each model it releases, until luma.gl does it itself.

Changes

  • MeshTextureLayer.finalizeState destroys the vertex arrays of the layer's models after SimpleMeshLayer destroys the models.
  • MeshTextureLayer.updateState destroys the old model's vertex array when SimpleMeshLayer replaces the model (on a new mesh, or on a render pipeline change, which the layer signals as extensionsChanged).
  • A vertex array that is already destroyed is skipped, so the workaround stays correct once luma.gl's Model.destroy() destroys it, and can then be removed.

Tests

  • New tests/mesh-layer/mesh-layer.test.ts renders the layer through deck.gl's LayerManager, with stand-in models and device since tests have no GPU.
  • It checks that the model's vertex array is destroyed when the layer is removed, that the old model's vertex array is destroyed (and the new one kept) when the mesh or the render pipeline changes, and that a vertex array Model.destroy() already destroyed isn't destroyed again.
  • 3 of the 4 new tests fail against main. The fourth (no double destroy) passes there by design and fails if the guard is removed.

Notes

  • luma.gl's Model.setBufferLayout() also replaces vertexArray without destroying the old one. deck.gl calls it only when an attribute's layout changes, so it should be rare here, and the layer can't reach that old vertex array.

Closes #765

🤖 Written by Claude Code

luma.gl's `Model.destroy()` (as of `@luma.gl/engine` 9.4.2) releases a
model's pipeline, shaders, uniform store and geometry, but never destroys
its vertex array. `SimpleMeshLayer` destroys its model when the layer is
finalized and when it rebuilds the model (on a new mesh, or on a render
pipeline change, which `MeshTextureLayer` signals as `extensionsChanged`),
so every tile ever drawn leaked one WebGL vertex array object for the life
of the context.

`MeshTextureLayer` now destroys the vertex array of each model it releases:
in `finalizeState`, and in `updateState` when `SimpleMeshLayer` replaced the
model. It skips a vertex array that is already destroyed, so it stays
correct once luma.gl destroys it itself and the workaround can be removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the fix label Oct 23, 2026
@kylebarron
kylebarron merged commit 2d62fde into main Oct 26, 2026
3 checks passed
@kylebarron
kylebarron deleted the kyle/destroy-vertex-arrays branch October 26, 2026 18:18
kylebarron added a commit to developmentseed/lonboard that referenced this pull request Nov 13, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Bumps:

- `@deck.gl/*` 9.4.0 →
[9.4.1](https://github.com/visgl/deck.gl/releases/tag/v9.4.1)
-
`@developmentseed/{deck.gl-raster,affine,morecantile,raster-reproject}`
0.8.1 →
[0.9.0](https://github.com/developmentseed/deck.gl-raster/releases/tag/v0.9.0)
→
[0.10.0](https://github.com/developmentseed/deck.gl-raster/releases/tag/v0.10.0)

The deck.gl overrides in `pnpm-workspace.yaml` go to `^9.4.1` too.
Without that, pnpm keeps every overridden deck.gl package at 9.4.0 and
only `@deck.gl/react` moves. deck.gl-raster 0.10 now depends on
`@developmentseed/range-reader`, so I added it to the commented-out
local-checkout overrides.

The breaking changes in deck.gl-raster 0.9 and 0.10 are in
`deck.gl-geotiff`, `deck.gl-zarr` and `geotiff`, which Lonboard doesn't
use. Lonboard only imports `RasterTileLayer`, `TileMatrixSetAdaptor` and
`MinimalTileData`, and needs no code changes.

Upstream fixes relevant to Lonboard:

- deck.gl-raster: tile textures are destroyed when a raster layer is
removed (developmentseed/deck.gl-raster#728), and a WebGL vertex array
no longer leaks per tile (developmentseed/deck.gl-raster#786).
- deck.gl-raster: missing TileMatrixSet bounds are inferred and `extent`
is honored (developmentseed/deck.gl-raster#684). The `TMSBoundingBox`
step in `examples/raster-titiler.ipynb` (#1327) should no longer be
needed. That isn't tested here.
- deck.gl: the MapLibre overlay container is removed with the overlay
(visgl/deck.gl#10899), and `GlobeController` can zoom past level 12
(visgl/deck.gl#10737).

The `beforeId` fix for interleaved MapLibre (visgl/deck.gl#10734) merged
after 9.4.1, so the `idle` workaround tracked in #1293 stays.

Supersedes Dependabot's #1350, which stops at deck.gl-raster 0.9.0.

Closes #1350

## Testing

- `pnpm build`, `pnpm check` and `pnpm test` (12 tests) pass.
- `uv run pytest` passes: 367 passed, 1 skipped, including `tests/ui`.
- `tsc --noEmit` reports the same 9 errors as `main`, and no new ones.
- No test covers `RasterLayer.from_geotiff`, the only path that uses
deck.gl-raster's `RasterTileLayer`. I checked it by hand with a
throwaway UI test. It opens a 2048×2048 EPSG:32618 COG with 3 overviews
and renders it with no basemap. Tiles reach the canvas on this branch
and on `main`, and the browser console output is the same on both.

🤖 Written by [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

luma.gl Model.destroy() leaks one vertex array per tile ever drawn

1 participant