Skip to content

fix(mesh-layers): signal ScenegraphLayer first draw once every model drew (1/2) - #11150

Open
charlieforward9 wants to merge 1 commit into
masterfrom
fix/scenegraph-first-draw
Open

charlieforward9 wants to merge 1 commit into
masterfrom
fix/scenegraph-first-draw

Conversation

@charlieforward9

@charlieforward9 charlieforward9 commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Follow up of #10058. Part 1 of 2, replacing #10784 with smaller changes; pacing follows in #11151.

ScenegraphLayer calls onFirstDraw after its first draw(), even when luma skipped a model's draw because its resources, such as glTF textures, are not ready: Model.draw() returns false then. Tile3DLayer marks the tile as drawn in onFirstDraw, so loaders.gl releases the tile's fallback parent before the replacement is visible.

Change List

  • ScenegraphLayer: call onFirstDraw once every model's draw returned true, and redraw until then
  • LayerColumns.draw: return whether luma drew
  • Unit tests

Verified with the mesh-layers and tile-3d-layer headless and node tests (the new tests fail on master) and the scenegraph-layer and simple-mesh-layer render tests.


Note

Low Risk
Low risk lifecycle timing fix that ensures onFirstDraw waits for all assets to finish loading, backed by targeted unit tests.

Overview
Updates ScenegraphLayer to only trigger onFirstDraw once every model in the scenegraph has successfully rendered. If any model or column batch skips rendering because resources such as glTF textures are still loading, the layer now defers signaling and schedules a redraw.

Additionally updates LayerColumns.draw to return a boolean indicating whether the batch draw completed, allowing ScenegraphLayer to verify draw completion across both column-based and standard model draws.

Reviewed by Cursor Bugbot for commit 2e3d708. Bugbot is set up for automated code reviews on this repo. Configure here.

…drew

ScenegraphLayer called onFirstDraw after its first draw even when luma
skipped a model's draw because its resources, such as glTF textures, were
not ready. Tile3DLayer marks the tile as drawn there, so loaders.gl
released the tile's fallback parent before the replacement was visible.

Signal onFirstDraw only after every model's draw (or column batch draw)
returned true, and request another frame until it does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects first-draw timing for scenegraph layers and tile replacement transitions.

The PR appears safe to merge, with a non-blocking gap in coverage of the column draw result.

Findings

  1. P2 Column draw result goes untested ▶

Summary

ScenegraphLayer now waits for every model to report a completed draw before calling onFirstDraw.

  • ScenegraphLayer waits for every model to draw before signaling its first draw.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Draw scenegraph models] --> B{Every draw returned true?}
  B -->|No| C[Request another frame]
  C --> A
  B -->|Yes| D{Already signaled?}
  D -->|No| E[Call onFirstDraw once]
  D -->|Yes| F[Continue drawing normally]
Loading

Reviews (1) · Last reviewed commit: "fix(mesh-layers): signal ScenegraphLayer..." · Reviewed by Greptile

Comment on lines +61 to +64
const draw = vi.fn().mockReturnValueOnce(false).mockReturnValue(true);
layer.state = {
scenegraph: new GroupNode([makeModelNode([])]),
columns: {loading: false, length: 1, draw}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Column draw result goes untested

This test replaces LayerColumns.draw with a mock, so it never checks the changed return path through model.drawBatches. Removing the new return would leave these tests passing while column-backed layers stop calling onFirstDraw.

Add a direct LayerColumns.draw test that checks both false and true results from drawBatches, plus the empty-column result.

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 83.591% (+0.003%) from 83.588% — fix/scenegraph-first-draw into master

@athomct athomct left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Head 2e3d708. Base master. Verdict: comment (approve after findings 1 and 2).

Summary

This PR makes ScenegraphLayer call onFirstDraw only after every model in the scenegraph reports a successful draw. Until then, the layer requests a redraw each frame. LayerColumns.draw now returns the result of model.drawBatches. The aim is correct: Tile3DLayer sets tileDrawn in onFirstDraw, and loaders.gl releases the fallback parent on that flag, so an early signal can open a hole while glTF textures load. The change works for the loading case. The new node tests and the scenegraph and simple-mesh render tests pass. I found one behaviour risk for draws that never succeed, and one test gap.

Findings

  1. modules/mesh-layers/src/scenegraph-layer/scenegraph-layer.ts:553-560 — should-fix — a draw that fails permanently redraws forever.
    Evidence: luma.gl Model.draw() returns false for more than loading resources. In luma.gl 10.0.0-beta.2 (GPUVectorModel._draw), it also returns false when the pipeline is errored and when vertexArray.getDrawValidationError() sets the sticky _drawBlockedReason. In those cases allModelsDrawn stays false on every frame. The layer then calls setNeedsRedraw() on every frame, so deck never goes idle. onFirstDraw never fires, so Tile3DLayer never sets tileDrawn. loaders.gl then holds the parent tile and re-runs selectTiles() with setTimeout for as long as the tile stays selected. Before this PR, the first draw call ended both loops. A minimal test shows the loop: a model whose draw always returns false, drawn 1000 times, gives 1000 setNeedsRedraw calls and no onFirstDraw call.
    Suggested change: retry only while resources load. For example, stop after a bounded number of frames and signal anyway, or ask luma.gl for a loading state and treat other failures as "drawn". Add a test for a model that never draws.

  2. modules/core/src/lib/layer-columns.ts:448 and :497 — should-fix — the new LayerColumns.draw return values have no test.
    Evidence: the column test mocks LayerColumns.draw, and the empty-column test uses an empty GroupNode, so LayerColumns.draw never runs. Two mutations survive the PR's tests: (a) remove return before model.drawBatches(...) (only tsc catches this one), and (b) change the empty-column result from true to false. Mutation (b) brings back finding 1 for every empty column-backed layer. The Greptile bot also flagged this gap.
    Suggested change: add a direct LayerColumns.draw test that checks true and false from drawBatches, and true for no prepared columns.

  3. test/modules/mesh-layers/scenegraph-columns.node.spec.ts — should-fix — the PR conflicts with master.
    Evidence: git merge-tree against master 69b44bd reports a content conflict in this test file. master also moved to luma.gl 10.0.0-beta.2. I checked that Model.draw() in beta.2 keeps the same false paths, so the fix still applies after a rebase.
    Suggested change: rebase on master and re-run the mesh-layers and tile-3d-layer tests.

  4. modules/mesh-layers/src/scenegraph-layer/scenegraph-layer.ts:143-147 — nit — document the new timing.
    The TSDoc now says the callback can take several frames. Please also say what happens when a model never draws, after you choose a fix for finding 1.

Tests run (local, macOS, headless Chromium)

  • Node: test/modules/mesh-layers, test/modules/geo-layers/tile-3d-layer: 8/8 pass.
  • Headless: test/modules/mesh-layers, test/modules/geo-layers/tile-3d-layer: 14/14 pass.
  • Render: scenegraph-layer.spec.ts, simple-mesh-layer.spec.ts: 20/20 pass.
  • Mutation check of the PR's tests: ignoring the draw result fails 2 tests (good). Dropping setNeedsRedraw fails 1 test (good). Dropping the drawBatches return survives. Changing the empty-column result to false survives.
  • Probe for finding 1: a model whose draw always returns false drew 1000 times with 1000 redraw requests and no first-draw signal.
  • Not run: tsc and lint.

This branch has not been deployed

No deployments
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.

4 participants