Skip to content

Commit c020394

Browse files
MarijnS95notgull
authored andcommitted
examples/drm: Don't force card{i} enumeration to start at 0
On my setup with an AMD RX6800XT GPU (same happens with an Intel Arc GPU) there is only `card1` and `renderD128`. The example would fail with a "File not found" error for `/dev/dri/card0` when it should instead continue to iterate to find the first valid DRM device. A more future-proof solution would be to replace the `0..10` range with a `readdir()`-like iterator over the contents of `/dev/dri` if that's accepted for an example.
1 parent 8a5343f commit c020394

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

examples/drm.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,14 @@ mod imple {
168168
fn find() -> Result<Card, Box<dyn std::error::Error>> {
169169
for i in 0..10 {
170170
let path = format!("/dev/dri/card{i}");
171-
let device = Card::open(path)?;
171+
// Card enumeration may not start at zero, allow failures while opening
172+
let Ok(device) = Card::open(path) else {
173+
continue;
174+
};
172175

173176
// Only use it if it has connectors.
174-
let handles = match device.resource_handles() {
175-
Ok(handles) => handles,
176-
Err(_) => continue,
177+
let Ok(handles) = device.resource_handles() else {
178+
continue;
177179
};
178180

179181
if handles

0 commit comments

Comments
 (0)