maplibre-contour: detached ArrayBuffer on a repeat contour request

LocalDemManager caches finished contour tiles and returns the cached ArrayBuffer itself. MapLibre transfers vector tile data to its own worker, and transferring detaches that buffer. Any later cache hit for the same tile then returns an empty, detached buffer.

This affects worker: false. With worker: true the result is copied before it is transferred back from the worker, so the cached copy stays intact.

Chromium reports attempting to access detached ArrayBuffer. Safari reports DataCloneError: The object can not be cloned.

Which build to test

?lib=published loads the published maplibre-contour 0.1.0 build, which shows the bug. ?lib=fixed loads the build from the pull request, which fixes it. Both files sit in lib/ next to this page.

Loaded build:

Test 1: no map, two requests for the same tile

This requests one contour tile, transfers the buffer the way MapLibre does, then requests the same tile again. No panning and no concurrency are needed.

Running...

Test 2: the same bug in a map

MapLibre only re-requests a tile after it evicts it, so panning may not show this quickly. Press the button instead. It reloads the source, which re-requests the same tiles while maplibre-contour still has them cached. Each error below is one tile that lost its contour lines.

No source errors yet.