-
Notifications
You must be signed in to change notification settings - Fork 50
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
Make raw_*_handle return a result #122
Conversation
This looks great, but I want others to have a chance to raise any concerns before we merge it. |
Sounds good! I'll loop in @ogoffart since this was originally their idea. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My primary objection to this is still: How will this look for the user? Like, how are they expected to actually handle the error?
As I see it, most people will just end up doing an unwrap
, since:
- They are correctly managing event lifecycles on Android, meaning that the handle will always be available.
- Or for Slint, the window they want to render into will be backed by a backend.
If any of those are not true, then that's a programmer error, and i.e. a good use of panics, not something that needs to be recoverable.
f, | ||
"The underlying handle cannot be represented using the types in this crate" | ||
), | ||
Self::Unavailable => write!(f, "The underlying handle is not available"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error Display
text should start with a lowercase letter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a precedent for this? I've always started my error messages with a capital letter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the Error
trait itself recommends it
#[non_exhaustive] | ||
pub enum RawHandleError { | ||
/// The underlying handle cannot be represented using the types in this crate. | ||
NotSupported, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use-case for this?
The use-case discussed in #104 would use Unavailable
, since that's what most accurately describes their situation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the library can't provide a any handle for the current platform, but still somehow built for it. Or when multiple could be provided at the same time, like XLIB and XCB, but it was compiled without xlib, so it'll be not-available in generic cfg less code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is that:
NotSupported
is when the underlying windowing system does not support returning any of the C window handles. For instance, if you're using a pure Rust implementation of X11 or Wayland, or if you're using something thatraw-window-handle
doesn't support (like a game console).Unavailable
is when the window is temporarily not available. The use case here is Android after a suspend event. There are probably others.
Handling these two error conditions may require separate code for certain cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be cool to have some of those example uses in the docs
Thanks for keeping me in the loop. I think that now that there are the safe handle, i'm not going to implement the But What is concerns me is the fact that it is a breaking change that this will require a semver version increase which will fragment the ecosystem. |
The I think
Agreed. Or alternatively use the semver trick to avoid the issues. |
If the choice is between "return an error" or "not returning an error", I would say we should return an error. On the Android winit backend, there is a case where the function panics if the window is currently suspended. I would rather return an error than panic in this case. |
We could have similar issue as Android with Wayland layer shell windows, so it's a good idea in general. Ack from me. |
I understand; I'm trying to figure out how the user is expected to handle that error? |
Any handling more graceful than a panic is a good idea, honestly. |
The tree of robust architecture must be refreshed from time to time with the blood of breaking changes. Making the To address the comments above, except for obvious cases that are blatantly programmer bugs (like using the wrong ordering in We already have a breaking change that needs to be made (the removal of |
What I'm not convinced of is that this isn't such a case? If the application has been suspended, you shouldn't even try to do any rendering, i.e. trying to access the window handle in that case is a "blatant programmer bug". It is not something the application can recover from, it is something that must change in the code. Am I missing something here? Is there a feasible way to recover? If someone can give me a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me whether this is a breaking change or not.
I think the CHANGELOG is sort of desynced, given that we have 0.5.2
on crates.io and the file is at 0.5.1
.
That's probably my fault on the changelog. I'm not sure I'll have time to look into it myself today, but I'll definitely have to fix it before the next release, yeah. |
This is a breaking change since it modifies the return value of a method of a trait in a backwards-incompatible way.
Fixed in #124 |
Then it should be stated in the changelog. |
This is a breaking change.
Let's say I create a windowing framework that may use either a pure Rust implementation of X11 or the if let Ok(handle) = my_window.window_handle() {
use_wgpu_to_render_to_this_handle(handle);
} else {
use_software_rasterization();
} Granted, a similar affect could be achieved with feature flags, but this is more idiomatic because it doesn't rely on out-of-band compiler mechanisms. For the if let Ok(handle) = my_window.window_handle() {
// Do rendering here.
}
// If we can't access the window handle, just do nothing. It's better than panicking
// here, especially in production.
Fixed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the examples @notgull!
I still feel like the argument is kinda weak, if the issue is that people make mistakes regarding lifetime management, then we should work on making that easier to avoid, not adding a hack to this library.
But I realize that I'm in the minority, and probably arguing about something fundamentally inconsequential, so I'll withdraw my objections.
@rib or @MarijnS95, if you have a moment could you provide your thoughts regarding Android. The |
NB there is also a potential wayland use case here too. The wayland winit backed currently jumps through significant hoops to make it look like there is no async configure where it can't return a valid handle beforehand. It leads to the whole backend buffering wayland events which shouldn't be necessary. |
That's not correct, the buffering is due to winit not using The Wayland use case I've mentioned above, and layer shell behaves exactly like Android, where surface destroys when you power off or dpms the output. So it's required for it as well. |
I might be misremembering some details but, from what I recall they are related. The backend wouldn't be needing to use If the backend could expose the fact that you can't query a raw handle until the configure comes back (asynchronously) from the compositor then it seems like it would be possible to remove any need for a round trip outside of the main event loop and so there would be no need to buffer events in the wayland backend. |
This change looks good to me, thanks! |
I think what we could do is to make a window return just |
Alright, it's been a week. Does anyone else have any comments before this is merged? I've already reached out to the cc @rust-windowing/winit, @rust-windowing/glutin, since you're the primary consumers of the |
Using Other than that, which you could consider non-blocking I guess, then I approve the PR. |
Is there going to be a "server trick" to avoid breaking the ecosystem? |
I'll try to if possible, see #125 |
This is a breaking change. Supersedes #104.