Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling improvements in chunk build threads #1794

Merged
merged 4 commits into from
Aug 1, 2023

Conversation

comp500
Copy link
Contributor

@comp500 comp500 commented Jun 6, 2023

I noticed in some recent issue reports that chunk build exceptions weren't being propagated to the main thread as intended in #615. This is because deferred (non-important) chunk builds aren't polled from the main thread using join() unlike important chunk rebuilds, and since 696da3c Sodium always treats initial chunk builds as deferred, so if a particular error makes a chunk never successfully build, join() will never be called on it!

This PR therefore correctly propagates these exceptions, along with extra handling for crash reporting that adds Sodium rendering context, with the following changes:

  • Added a queue to store chunk build failures in ChunkBuilder
  • Modified scheduleDeferred to add CompletableFuture exceptions to this queue
  • Created handlePendingFailures in RenderSectionManager to drain the failure queue and throw any found exception
  • Modified WorkStealingFutureDrain.findNext to unwrap CompletionExceptions that contain CrashException so that the crash report context is preserved
  • Wrapped the ChunkRenderRebuildTask.performBuild outer loop in a try-catch block to handle exceptions from chunk building and add chunk section / render context information
  • Improved RenderSection.toString to provide more useful information
  • Changed ChunkBuilder.processJob to use the Sodium logger rather than printStackTrace

For scheduleDeferred I changed it to use whenComplete as it doesn't wrap the exception in CompletionException (so any CrashException can be propagated directly) and it allows us to return CompletableFuture<ChunkBuildResult> matching the return type of schedule.

This is what the crash report context looks like:

-- Block being rendered --
Details:
	Block: Block{minecraft:gravel}
	Block location: World: (-16,-16,-48), Section: (at 0,0,0 in -1,-1,-3; chunk contains blocks -16,-64,-48 to -1,319,-33), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,-64,-512 to -1,319,-1)
	Chunk section: RenderSection at chunk (-1, -1, -3) from (-16, -16, -48) to (0, 0, -32)
	Render context volume: BlockBox{minX=-18, minY=-18, minZ=-50, maxX=1, maxY=1, maxZ=-31}

@jellysquid3 jellysquid3 added this to the Sodium 0.5 milestone Jul 5, 2023
@jellysquid3
Copy link
Member

jellysquid3 commented Jul 31, 2023

Can you rebase this against the /dev branch? We changed a lot to do with the ChunkBuilder but the crash report functionality you added should still work. We also now store a "job output" queue which the main thread polls every frame, and it handles unwrapping any exceptions if they exist. And because of this, there is now only one location where the results get unwrapped, making it a lot easier to report these exceptions.

comp500 added 2 commits August 1, 2023 13:02
Added a queue to store chunk build failures in `ChunkBuilder`
Modified `scheduleDeferred` to add `CompletableFuture` exceptions to this queue
Created `handlePendingFailures` in `RenderSectionManager` to drain the failure queue and throw any found exception
Modified `WorkStealingFutureDrain.findNext` to unwrap `CompletionException`s that contain `CrashException` so that the crash report context is preserved
Wrapped the `ChunkRenderRebuildTask.performBuild` outer loop in a try-catch block to handle exceptions from chunk building and add chunk section / render context information
Improved `RenderSection.toString` to provide more useful information
Changed `ChunkBuilder.processJob` to use the Sodium logger rather than `printStackTrace`

Rebased atop 7aba7c7 on 01/08/23:
Modified `ChunkJobResult.unwrap` to unwrap `CompletionException`s that contain `CrashException` so that the crash report context is preserved
Wrapped the `ChunkRenderMeshingTask.performBuild` outer loop in a try-catch block to handle exceptions from chunk building and add chunk section / render context information
Improved `RenderSection.toString` to provide more useful information
Updated `ChunkJobTyped.execute` to use the Sodium logger (there may be multiple chunk build errors before the main thread gets the results and aborts, so it's useful to log everything)
@comp500 comp500 force-pushed the fixes/chunkbuildcrashreporting branch from 9c7447e to 03668ab Compare August 1, 2023 12:21
@comp500
Copy link
Contributor Author

comp500 commented Aug 1, 2023

Updated list of changes after rebase:

  • Added a queue to store chunk build failures in ChunkBuilder
  • Modified scheduleDeferred to add CompletableFuture exceptions to this queue
  • Created handlePendingFailures in RenderSectionManager to drain the failure queue and throw any found exception
  • Modified WorkStealingFutureDrain.findNext ChunkJobResult.unwrap to unwrap CompletionExceptions that contain CrashException so that the crash report context is preserved
  • Wrapped the ChunkRenderMeshingTask.performBuild outer loop in a try-catch block to handle exceptions from chunk building and add chunk section / render context information
  • Improved RenderSection.toString to provide more useful information
  • Updated ChunkJobTyped.execute to use the Sodium logger (there may be multiple chunk build errors before the main thread gets the results and aborts, so it's useful to log everything)

@comp500 comp500 changed the base branch from 1.20/stable to dev August 1, 2023 12:21
@jellysquid3
Copy link
Member

Changes look good to me outside of minor nitpicks; will merge when resolved.

@jellysquid3 jellysquid3 merged commit 08cc0e3 into CaffeineMC:dev Aug 1, 2023
IMS212 pushed a commit to IMS212/sodium-fabric that referenced this pull request Aug 6, 2024
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.

3 participants