Skip to content

feat: opt-in/throttled CPU elevation readback with error handling - #23

Open
kenjinp wants to merge 2 commits into
mainfrom
feat/essk-readback-control
Open

kenjinp wants to merge 2 commits into
mainfrom
feat/essk-readback-control

Conversation

@kenjinp

@kenjinp kenjinp commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Summary

The GPU→CPU elevation readback ran unconditionally and any readback failure went unhandled (readbackPending could stick, buffers could half-swap).

  • New params terrainReadbackEnabled (default true) and terrainReadbackIntervalMs (default 0), exposed as React Terrain props / TerrainOptions.
  • terrainReadbackTask keeps per-instance throttle state in its own returned value (no module-scope state); gating logic is a pure shouldScheduleReadback() in query/readback-schedule.ts with unit tests.
  • triggerSnapshotReadback now returns whether a readback was scheduled, .catches both the device and getArrayBufferAsync paths, never swaps buffers on failure, resets readbackPending, resets the stamp so the next run retries, and logs each distinct error once.
  • When disabled: queries return { valid: false } / null, raycast falls back to bounds-only picking, LOD uses the datum surface (documented).
  • Docs: params table, query/raycast pages, React props, changelog.

Verification

  • typecheck, lint, vitest (16 files / 80 tests) pass.
  • Bugbot adversarial review found that with the default memo cache the task body would not re-run when upstream deps were stable, so a throttled/pending-skipped readback could stall until the next dependency change. Fixed by marking the task .cache("none") (its body is a few comparisons when nothing needs scheduling; prev still flows via task.value).

Notes

  • Touches the changelog "Unreleased" section like the other open PRs; expect a trivial merge conflict there.
  • Beans: hello-terrain-essk.

Made with Cursor

…eadback error handling

- Add terrainReadbackEnabled (default true) and terrainReadbackIntervalMs
  (default 0) params; terrainReadbackTask no-ops when disabled and throttles
  by wall-clock interval using task-local state (no module scope).
- triggerSnapshotReadback / CpuTerrainCache.triggerReadback return whether a
  readback was scheduled so the throttle timestamp only advances on real work.
- Catch readback failures on both the pooled and getArrayBufferAsync paths:
  reset readbackPending, never swap buffers, retry on next run, and log each
  distinct error once per snapshot state.
- React: terrainReadback / terrainReadbackIntervalMs options on useTerrain and
  <Terrain>, wired through useTerrainParams.
- Tests for the gating helper, the snapshot failure path, and the React
  option mapping.
- Docs: Controlling readback section, params/useTerrain tables, topology link,
  changelog entry.
- Bean hello-terrain-essk marked completed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant