Skip to content

Keep sorting after a sort fails - #511

Open
vanyathecyborg wants to merge 1 commit into
sparkjsdev:mainfrom
vanyathecyborg:contrib/sort-lock
Open

vanyathecyborg wants to merge 1 commit into
sparkjsdev:mainfrom
vanyathecyborg:contrib/sort-lock

Conversation

@vanyathecyborg

Copy link
Copy Markdown

driveSort sets sorting before it reads depths back and calls the sort worker, and cleared it only on its last line. If either rejected, the flag stayed set for the life of the renderer: no sort started again, and an update that changes the splat mapping waits for the running sort. A lost WebGL context is enough to get there: it rejects the readback, and after the context is restored nothing is drawn.

The flag is now cleared in a finally block, the failed sort is asked for again on the next update, and the error is rethrown as before. A sort worker that trapped is disposed and replaced on that next sort, as the pool does for its own workers since #480, which left SparkRenderer's sort worker unchanged.

Verification

  • New browser test context-loss.test.ts: it loses the WebGL context, restores it, and expects the same image as before the loss.
    • On main it fails: sorting stays true, the renderer never sorts again, and the canvas stays black.
    • With this change it passes.
  • Two new unit tests, a sort that rejects and a sort worker that traps, fail on main and pass with this change.
  • Lint, unit tests and the full browser suite pass.

Open question

A sort that keeps failing is retried on every update and reported each time. #477 stopped a similar retry for LoD trees. I kept it here because without it a pending mapping change is never shown while the camera stands still. I can add a limit if you prefer.

Related to #480.

🤖 Generated with Claude Code

driveSort sets `sorting` before it reads depths back and calls the sort
worker, and cleared it only on its last line. If the readback or the
worker call rejected, the flag stayed set for the life of the renderer:
no sort started again, and an update that changes the splat mapping waits
for the running sort. A lost WebGL context is enough: it rejects the
readback, and once the context is restored nothing is drawn.

The sort body moves into sortCurrent(), and driveSort clears the flag in
a finally block. After a failure it marks the sort as still wanted, so
the next update starts it again, and rethrows the error as before.

A sort worker that trapped is disposed and replaced on that next sort, as
the worker pool does for its own workers since sparkjsdev#480: a trap leaves the
WebAssembly instance unusable, so the retry would fail the same way.

Two unit tests cover a rejected sort that runs again on the next frame
and a trapped worker that is not used again. A browser test loses and
restores the WebGL context and expects the same image as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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