Skip to content

[egl] get rid of unwrap where possible #8024

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

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

uael
Copy link
Contributor

@uael uael commented Jul 30, 2025

Description
This try to handle egl errors instead of panicking out. I left some unwrap and expect where no Result was returned.

Testing
Manually tested.

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@uael uael requested a review from a team as a code owner July 30, 2025 06:26
@uael uael force-pushed the uael/egl_less_panics branch 2 times, most recently from a5736e2 to ef685ac Compare July 30, 2025 13:25
@cwfitzgerald cwfitzgerald self-assigned this Jul 30, 2025
@uael uael force-pushed the uael/egl_less_panics branch 2 times, most recently from 8a36522 to dd86d76 Compare August 4, 2025 12:44
@jimblandy jimblandy assigned Wumpf and unassigned cwfitzgerald Aug 6, 2025
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

nice, way better. Some nits, but otherwise good to go

library.get(c"XOpenDisplay".to_bytes()).unwrap();
let func: libloading::Symbol<XOpenDisplayFun> = library
.get(c"XOpenDisplay".to_bytes())
.inspect_err(|err| log::error!("Failed to load XOpenDisplay: {err:?}"))
Copy link
Member

Choose a reason for hiding this comment

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

feels like we should have an error category for failing to load methods which we can propagate. But this is already strictly better 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure? This changes the semantics a little bit, as if there was no X display that could be opened because standard functions that should theoretically always be there were not found (I doubt that could/should ever happen, hence unwrap()/expect() make sense).

Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

ah, sorry one more thing: could you please add a mention in the changelog under bugfixes? thanks!

@uael uael force-pushed the uael/egl_less_panics branch 2 times, most recently from 573fe50 to d4eda9f Compare August 11, 2025 09:23
uael and others added 2 commits August 11, 2025 11:30
Co-authored-by: Andreas Reich <r_andreas2@web.de>
@uael uael force-pushed the uael/egl_less_panics branch from 4387f91 to e6a83f1 Compare August 11, 2025 09:30
@uael
Copy link
Contributor Author

uael commented Aug 11, 2025

Just to add a bit of context, this is fixing an unwrap failed for some Android devices while creating a context. Unfortunately, the stack-trace I had access to wasn't precise enough to know which one was failing, but after this commit no more crash (nor errors) so I suspect one in configuration dump

Comment on lines +513 to +517
fn instance_err<E: core::error::Error + Send + Sync + 'static>(
message: impl Into<String>,
) -> impl FnOnce(E) -> crate::InstanceError {
move |e| crate::InstanceError::with_source(message.into(), e)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be much clearer if wgpu could define an anyhow-like context() trait for every Result. That should make it a lot less likely to loose source errors with other(), that I see a bunch of PRs do.

library.get(c"XOpenDisplay".to_bytes()).unwrap();
let func: libloading::Symbol<XOpenDisplayFun> = library
.get(c"XOpenDisplay".to_bytes())
.inspect_err(|err| log::error!("Failed to load XOpenDisplay: {err:?}"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure? This changes the semantics a little bit, as if there was no X display that could be opened because standard functions that should theoretically always be there were not found (I doubt that could/should ever happen, hence unwrap()/expect() make sense).

@@ -91,6 +91,10 @@ By @Vecvec in [#7913](https://github.com/gfx-rs/wgpu/pull/7913).

- Fixed a bug where access to matrices with 2 rows would not work in some cases. By @andyleiserson in [#7438](https://github.com/gfx-rs/wgpu/pull/7438).

##### EGL

- Fixed unwrap failed in context creation for some Android devices. By @uael in [#8024](https://github.com/gfx-rs/wgpu/pull/8024).
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not seem to match the title of the PR. This only intends to add context right? Not fix any actual bugs, this changelog being under ### Bug Fixes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I added after #8024 (review)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I remove it ?

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.

4 participants