-
Notifications
You must be signed in to change notification settings - Fork 194
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
[RFC] Error handling #41
Comments
Seems a bit inconsistent to return a tuple in some cases and |
That seems reasonable, I am also leaning more towards custom success enums. Alternatively I think I could also just keep it as it currently is, but return all success error codes in the
Thoughts? |
I like that
… On Dec 30, 2017, at 06:49, Maik Klein ***@***.***> wrote:
That seems reasonable, I am also leaning more towards custom success enums. Alternatively I think I could also just keep it as it currently is, but return all success error codes in the Ok variant.
pub unsafe fn acquire_next_image_khr(
&self,
swapchain: vk::SwapchainKHR,
timeout: vk::uint64_t,
semaphore: vk::Semaphore,
fence: vk::Fence,
) -> VkResult<vk::uint32_t> {
let mut index = mem::uninitialized();
let err_code = self.swapchain_fn.acquire_next_image_khr(
self.handle,
swapchain,
timeout,
semaphore,
fence,
&mut index,
);
match err_code {
vk::Result::Success | vk::Resut::SubObtimalKHR | vk::Result::Timeout | .. => Ok(index),
_ => Err(err_code),
}
}
Thoughts?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I agree. I meant more like |
I like the idea of changing all of the functions to return Is it safe to assume that all success codes are positive and all error codes are negative? If so, that means this change is largely mechanical. |
@LPGhatguy Yes, spec guarantees that errors are negative and successes are positive (or 0 in case of VK_SUCCESS). @MaikKlein I'm leaning more towards the Result<(T, SuccessCode), ErrorCode> version. In your example, consuming success code and returning just the index might not work for all success codes. For example, I think VK_TIMEOUT would not give you valid index, thus consuming status and just returning the index would be an error. Likewise, even if you get valid index, you may want to react to VK_SUBOPTIMAL_KHR and recreate swapchain anyway. |
I think
I think this would be more consistent with the rest of the api.
|
There is only one nonzero |
There are function which convert a successful return code into an error.
For example
acquire_next_image
may returnVK_SUBOPTIMAL_KHR
among other codes, indicating that the return index could still be used but the swapchain doesn't match the surface anymore. In the current API, this would return an error.My suggestion would be to return a tuple of
(ReturnType, SuccessCode)
in these cases.The text was updated successfully, but these errors were encountered: