Say which backend was chosen without claiming it was the first

Two corrections to the message, both reported by CodeRabbit on #1371.

switched_from being None only means this start did not switch from a
backend that never showed a frame. A backend that failed on an earlier
start is remembered in the record, and choose() then picks the first
candidate that is not in that list -- so calling it the "first choice"
misstates how it was arrived at. The line now says either "nothing has
failed before" or which backends had, so the log says what happened.

The comment claimed that reaching this line means WGPU_BACKEND is
unset. wgpu-types returns an empty mask for an empty or unrecognised
value and begin() only returns early for a non-empty one, so such a
value reaches here with the variable set. The comment says that instead.
This commit is contained in:
Hamza committed 2026-10-20 20:59:04 +05:00
1 parent e572a5316f
commit ba4b6d4089
1 file changed
+15 -4
+15 -4
View File
@@ -231,10 +231,21 @@ impl Fallback {
choice.backend.name(),
choice.record.failed
),
// `begin` returns before this when `WGPU_BACKEND` is set, so reaching here means it is
// not: the message said the opposite, which reads in a log as though the user's
// environment had chosen the backend (#1343).
None => log::info!("graphics: {} (first choice; set WGPU_BACKEND to choose another)", choice.backend.name()),
// Not a switch from an unfinished start. `begin` has already returned when
// `WGPU_BACKEND` names a backend, so wgpu is not being told which to use here -- an
// empty or unrecognised value is no choice and reaches this line like an unset one.
// The message used to say the environment had been asked, which reads in a log as
// though the user had chosen the backend (#1343). What this start did choose is
// either the first candidate or the first one that has not failed before, so it says
// which of the two it is rather than claiming the first choice.
None if choice.record.failed.is_empty() => {
log::info!("graphics: {} (nothing has failed before; set WGPU_BACKEND to choose another)", choice.backend.name())
}
None => log::info!(
"graphics: {} (the first that hasn't failed before, after {:?}; set WGPU_BACKEND to choose another)",
choice.backend.name(),
choice.record.failed
),
}
let instance = instance_backends(choice.backend, &choice.record.failed);
Some(Fallback { backend: choice.backend, switched_from: choice.switched_from, instance, path, record: choice.record })