From 579c392a9e2c7129f26459c1423be6f38e645538 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Mon, 28 Oct 2024 10:17:42 +0100 Subject: [PATCH] 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. --- examples/drm.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/drm.rs b/examples/drm.rs index 8e50125..a5f6de3 100644 --- a/examples/drm.rs +++ b/examples/drm.rs @@ -168,12 +168,14 @@ mod imple { fn find() -> Result> { for i in 0..10 { let path = format!("/dev/dri/card{i}"); - let device = Card::open(path)?; + // Card enumeration may not start at zero, allow failures while opening + let Ok(device) = Card::open(path) else { + continue; + }; // Only use it if it has connectors. - let handles = match device.resource_handles() { - Ok(handles) => handles, - Err(_) => continue, + let Ok(handles) = device.resource_handles() else { + continue; }; if handles