-
Notifications
You must be signed in to change notification settings - Fork 59
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
Builder pattern allows invalid usage #163
Comments
I'm not sure this is worth pursuing. Large argument lists can significantly degrade readability compared to populating struct fields, and IIRC OpenXR guarantees graceful error detection for this case, so there is no safety issue. We can't statically prevent erroneous inputs in general, so we should be wary of worsening ergonomics in exchange for handling a few marginal cases. |
I think the spec doesn't guarantee graceful error detection:
But I agree that it may not be worth the extra complexity. |
If UB is possible in a safe API, then we need to at least insert such checks ourselves, or the API is unsound. |
Adding asserts to all relevant functions seems like a good solution. It doesn't change the API. Should I go through all structs/functions and create a PR? |
That would be very welcome! Note that handling this correctly for |
The generated builders zero out all fields other than
ty
when created.Some structures aren't valid with zeroed out fields, but they can be submitted to functions anyway.
Some examples:
XrCompositionLayerProjection::viewCount
must be greater than 0.XrCompositionLayerProjection::space
must be a validXrSpace
handle.XrInteractionProfileDpadBindingEXT::actionSet
must be a validXrActionSet
handleThe solution to this is probably to take all required fields as arguments to the
new
functions instead of using a builder.I will work on a PR for this.
The text was updated successfully, but these errors were encountered: