Skip to content

Re-check supported alpha modes in configure_surface - #3532

Open
Fee0 wants to merge 1 commit into
iced-rs:masterfrom
Fee0:fix/reconfigure-alpha-mode
Open

Fee0 wants to merge 1 commit into
iced-rs:masterfrom
Fee0:fix/reconfigure-alpha-mode

Conversation

@Fee0

@Fee0 Fee0 commented Nov 7, 2026

Copy link
Copy Markdown

iced_wgpu picks the surface alpha mode once at startup and reuses it in every configure_surface. But the supported modes can change during a surface's lifetime: on Windows with Vulkan and vsync off, an NVIDIA driver (RTX 3060 Ti, 595.71) offers [Opaque, PreMultiplied] for the first two swapchains and only [Opaque] afterwards. The next resize then panics:

In Surface::configure
  Requested alpha mode PreMultiplied is not in the list of supported alpha modes: [Opaque]

This PR queries the surface capabilities on every configure and picks the mode from what is supported right now (same preference as before: PreMultiplied, else Auto). This also fixes multi-window apps reusing the mode probed on the first window.

Repro (Windows, Vulkan)

use iced::backend::Api;
use iced::{Backend, Element, Settings, Size, Task, Widget as _, time, widget::text, window};
use std::time::Duration;

fn main() -> iced::Result {
    let settings = Settings {
        backend: Backend::Hardware(Api::Vulkan),
        vsync: false,
        ..Settings::default()
    };

    iced::application(|| 0, update, view)
        .settings(settings)
        .subscription(|_| time::every(Duration::from_millis(100)).map(|_| ()))
        .run()
}

fn update(resizes: &mut u32, _tick: ()) -> Task<()> {
    *resizes += 1;
    let size = if *resizes % 2 == 0 { Size::new(800.0, 600.0) } else { Size::new(600.0, 400.0) };
    window::latest().and_then(move |id| window::resize(id, size))
}

fn view(resizes: &u32) -> Element<'_, ()> {
    text!("{resizes} resizes").boxed()
}

The alpha modes a surface supports can change during its lifetime (e.g. Vulkan with vsync off on NVIDIA drops `PreMultiplied` after the first swapchains), so the mode picked at startup could be rejected later and panic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant