Skip to content

vello_hybrid: Streamline error handling in the WebGL backend#1588

Draft
LaurenzV wants to merge 1 commit into
mainfrom
laurenz/errors
Draft

vello_hybrid: Streamline error handling in the WebGL backend#1588
LaurenzV wants to merge 1 commit into
mainfrom
laurenz/errors

Conversation

@LaurenzV
Copy link
Copy Markdown
Collaborator

Right now, we have a relatively inconsistent approach of error handling, returning errors in some cases but just unwrapping in other cases. This PR attempts to improve the situation by adding more robust error handling to the WebGL backend. Something similar should be done in the wgpu backend, but that is left for a future PR.

In a few cases, it was often not straightforward to decide whether something should become an error or be unwrapped. I've tried to follow the principle of unwrapping in all cases where it should be impossible to fail (i.e. max_texture_dimension returning a non-numeric value), while using errors anywhere else where it could reasonably fail. Alternatively, we could add a final Unknown(String) error variant where we combine all errors that should in theory never happen, and thus ensure that the backend never crashes, even if something really unexpected happens.

AtlasError(#[from] vello_common::multi_atlas::AtlasError),
// TODO: Consider expanding `RenderError` to replace some `.unwrap` and `.expect`.
/// A WebGL operation failed during rendering.
#[cfg(all(target_arch = "wasm32", feature = "webgl"))]
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if it's a good idea to feature gate an error variant, open for other suggestions! Maybe WebGL errors should just always be available? Or I guess there could be a generic error type where WebGL and wgpu can insert their own internal error type.

@LaurenzV LaurenzV requested a review from taj-p April 20, 2026 07:25
@LaurenzV LaurenzV marked this pull request as draft April 20, 2026 07:30
@LaurenzV
Copy link
Copy Markdown
Collaborator Author

Hmm, I think if we want to have something like this we need to think a bit more about what a user is supposed to do in case they encounter an error and document that. I think ideally, once any kind of error is encountered the user is expected to not do anything with the renderer anymore and completely discard it. However, if we switch to this result-based API, users might be inclined to just try reusing the context, which is bad because at that point the whole renderer might be in an inconsistent state (for example, pending bitmap uploads will be completely drained even if not all bitmap glyphs have been uploaded.

I think just documenting that "error encountered = don't perform any further operations with the renderer" might be enough, but perhaps this warrants some more discussion.

let context_attributes = gl.get_context_attributes().unwrap();
let context_attributes = gl
.get_context_attributes()
.expect("WebGL context attributes should be available");
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Note to self: This can probably fail if the WebGL context has been lost.

@taj-p
Copy link
Copy Markdown
Contributor

taj-p commented Apr 21, 2026

Hmm, I think if we want to have something like this we need to think a bit more about what a user is supposed to do in case they encounter an error and document that. I think ideally, once any kind of error is encountered the user is expected to not do anything with the renderer anymore and completely discard it. However, if we switch to this result-based API, users might be inclined to just try reusing the context, which is bad because at that point the whole renderer might be in an inconsistent state (for example, pending bitmap uploads will be completely drained even if not all bitmap glyphs have been uploaded.

I think just documenting that "error encountered = don't perform any further operations with the renderer" might be enough, but perhaps this warrants some more discussion.

We could poison the renderer similar to how a mutex is poisoned, but that doesn't solve the resources problem 🤔 . I'll raise it in the OH tomorrow

Copy link
Copy Markdown
Contributor

@taj-p taj-p left a comment

Choose a reason for hiding this comment

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

Re-request review once you're ready 🙏

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