iced icon indicating copy to clipboard operation
iced copied to clipboard

A lot of examples in `iced` are not working

Open VarLad opened this issue 2 years ago • 24 comments

Tried the clock, game_of_life, integration_wgpu examples in iced

All give the same error

thread 'main' panicked at 'Error in Surface::configure: parent device is lost', /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.12.0/src/backend/direct.rs:214:9

Other examples like, stopwatch, pokedex work awesome!

Does anyone know the reason?

VarLad avatar Jan 09 '22 08:01 VarLad

It may be related to the Settings::antialiasing flag, which is enabled on both the clock and game_of_life examples:

https://github.com/iced-rs/iced/blob/1a31aefab401712e44cd613fc1337ab90579d926/examples/clock/src/main.rs#L9 https://github.com/iced-rs/iced/blob/1a31aefab401712e44cd613fc1337ab90579d926/examples/game_of_life/src/main.rs#L22

Your hardware or graphics drivers may not properly support this feature. I recommend you to try the wgpu examples and report any issues in their repository.

hecrj avatar Jan 10 '22 09:01 hecrj

Most of the wgpu examples I tried worked without a problem

VarLad avatar Jan 10 '22 11:01 VarLad

~~I probably should've mentioned this but the problem is specific to Wayland~~

The examples that don't work on Wayland crash upon resizing in X11 with the same error as above

VarLad avatar Jan 10 '22 21:01 VarLad

~~All wgpu examples run perfectly without issues, leading me to believe that its an issue in iced~~

Might be a wgpu problem I guess https://github.com/gfx-rs/wgpu/issues/1974

VarLad avatar Jan 10 '22 22:01 VarLad

I don't think it's related to https://github.com/gfx-rs/wgpu/issues/1974 This sounds more like a window-system-integration (WSI) issue here. I'm a bit confused by the reports on the examples because it's not clear if Iced examples are in the context or wgpu examples. Do wgpu examples crash for you upon resize?

kvark avatar Jan 11 '22 16:01 kvark

@kvark

I'm a bit confused by the reports on the examples because it's not clear if Iced examples are in the context or wgpu examples.

wgpu examples all run on both X11 and Wayland without any problems. Its the iced examples which don't run on Wayland giving the above error, and crash on resizing in X11 again giving the same error

VarLad avatar Jan 12 '22 01:01 VarLad

@kvark (sorry for pinging :sweat_smile: )

Any way I can help debug and fix this issue? Maybe something that I should try running and posting logs of?

VarLad avatar Jan 13 '22 09:01 VarLad

I'd try to see what the differences are between wgpu and iced examples. I.e. start with a wgpu example, and add iced as a dependency, then do the things that iced examples do. See when it starts breaking.

kvark avatar Jan 13 '22 16:01 kvark

@kvark I don't use iced library so that might be a bit hard for me 😅 Maybe the difference between the examples that run and the examples that don't might help?

VarLad avatar Jan 13 '22 18:01 VarLad

I'm not able to build iced on my main machine currently because of https://github.com/servo/fontconfig/issues/10 I can try a different machine later, but that one has AMD. Basic process we need here is trying to reduce the test case to the minimum for reproducing the bug. Minimum in terms of wgpu usage, not iced.

kvark avatar Jan 13 '22 19:01 kvark

@kvark Here's the crash report on X11 (after some resizing) There's no "pattern" to when or how do I resize that it crashes. Its pretty random as far as I can see

/home/username/iced(master)> RUST_BACKTRACE=full cargo run --package game_of_life
    Finished dev [unoptimized + debuginfo] target(s) in 0.19s
     Running `target/debug/game_of_life`
thread 'main' panicked at 'Error in Surface::configure: parent device is lost', /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.12.0/src/backend/direct.rs:214:9
stack backtrace:
   0:     0x55bd04d8da3c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3264ad1edb4a78ca
   1:     0x55bd04db055c - core::fmt::write::h85b247e856e081ad
   2:     0x55bd04d88b75 - std::io::Write::write_fmt::he3b80a66fc2ba5d3
   3:     0x55bd04d8f660 - std::panicking::default_hook::{{closure}}::hf2bcdea8e51c0c13
   4:     0x55bd04d8f215 - std::panicking::default_hook::h8864cfaaed08e53a
   5:     0x55bd04d8fd14 - std::panicking::rust_panic_with_hook::hb272975096b9f3ce
   6:     0x55bd04d8f7f0 - std::panicking::begin_panic_handler::{{closure}}::hbbd6c4e11858ba52
   7:     0x55bd04d8df04 - std::sys_common::backtrace::__rust_end_short_backtrace::hdd56e8729123abc5
   8:     0x55bd04d8f759 - rust_begin_unwind
   9:     0x55bd03c8b9ab - std::panicking::begin_panic_fmt::hd76138c622de6537
  10:     0x55bd040b1f7a - wgpu::backend::direct::Context::handle_error_fatal::ha0255c27d5a003d8
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.12.0/src/backend/direct.rs:214:9
  11:     0x55bd040b3956 - <wgpu::backend::direct::Context as wgpu::Context>::surface_configure::h3a2c6b637f89e012
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.12.0/src/backend/direct.rs:921:13
  12:     0x55bd03f844cd - wgpu::Surface::configure::hddb44dc4040dac21
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.12.0/src/lib.rs:3267:9
  13:     0x55bd03e0d216 - <iced_wgpu::window::compositor::Compositor as iced_graphics::window::compositor::Compositor>::configure_surface::hb6dc9fb70020e12d
                               at /home/username/iced/wgpu/src/window/compositor.rs:124:9
  14:     0x55bd03da98d7 - iced_winit::application::run_instance::{{closure}}::h38535696a18758eb
                               at /home/username/iced/winit/src/application.rs:382:21
  15:     0x55bd03d0fdbb - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h55bc52091ab264db
                               at /builddir/build/BUILD/rustc-1.57.0-src/library/core/src/future/mod.rs:80:19
  16:     0x55bd03dac6e9 - iced_winit::application::run::{{closure}}::ha15e244e1e2462fc
                               at /home/username/iced/winit/src/application.rs:207:24
  17:     0x55bd03dae872 - winit::platform_impl::platform::sticky_exit_callback::he67190346d39437f
                               at /home/username/.cargo/git/checkouts/winit-57d3141eaf559308/02a1238/src/platform_impl/linux/mod.rs:753:5
  18:     0x55bd03d5ece4 - winit::platform_impl::platform::x11::EventLoop<T>::run_return::h10875d31c38ec685
                               at /home/username/.cargo/git/checkouts/winit-57d3141eaf559308/02a1238/src/platform_impl/linux/x11/mod.rs:310:21
  19:     0x55bd03dadbae - winit::platform_impl::platform::EventLoop<T>::run_return::had4dceb1328d6af2
                               at /home/username/.cargo/git/checkouts/winit-57d3141eaf559308/02a1238/src/platform_impl/linux/mod.rs:662:56
  20:     0x55bd03d2145d - <winit::event_loop::EventLoop<T> as winit::platform::run_return::EventLoopExtRunReturn>::run_return::ha46e60bc3e6928be
                               at /home/username/.cargo/git/checkouts/winit-57d3141eaf559308/02a1238/src/platform/run_return.rs:56:9
  21:     0x55bd03dac162 - iced_winit::application::run::hbaac568e00b9bdb4
                               at /home/username/iced/winit/src/application.rs:182:5
  22:     0x55bd03cd93c2 - iced::application::Application::run::hba7f665a00a563fc
                               at /home/username/iced/src/application.rs:215:16
  23:     0x55bd03d2b720 - game_of_life::main::h4c77da4fa2ed6757
                               at /home/username/iced/examples/game_of_life/src/main.rs:21:5
  24:     0x55bd03d34b52 - core::ops::function::FnOnce::call_once::hec6f89f8955262f4
                               at /builddir/build/BUILD/rustc-1.57.0-src/library/core/src/ops/function.rs:227:5
  25:     0x55bd03d10aaa - std::sys_common::backtrace::__rust_begin_short_backtrace::h72d2d2bac68dbb65
                               at /builddir/build/BUILD/rustc-1.57.0-src/library/std/src/sys_common/backtrace.rs:123:18
  26:     0x55bd03ca9546 - std::rt::lang_start::{{closure}}::h3ff8839ceeba49e9
                               at /builddir/build/BUILD/rustc-1.57.0-src/library/std/src/rt.rs:146:18
  27:     0x55bd04d8d71b - std::rt::lang_start_internal::hcbc5d1079a591413
  28:     0x55bd03ca9510 - std::rt::lang_start::hb54c7579084a2280
                               at /builddir/build/BUILD/rustc-1.57.0-src/library/std/src/rt.rs:145:17
  29:     0x55bd03d2d5bc - main
  30:     0x7f9058648560 - __libc_start_call_main
  31:     0x7f905864860c - __libc_start_main@@GLIBC_2.34
  32:     0x55bd03c8cd55 - _start
  33:                0x0 - <unknown>

And here's the crash report for Wayland. It doesn't run at all in Wayland, with this crash report.

/home/username/iced(master)> RUST_BACKTRACE=full cargo run --package game_of_life
    Finished dev [unoptimized + debuginfo] target(s) in 0.19s
     Running `target/debug/game_of_life`
thread 'main' panicked at 'Error in Surface::configure: parent device is lost', /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.12.0/src/backend/direct.rs:214:9
stack backtrace:
   0:     0x5565a21eda3c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3264ad1edb4a78ca
   1:     0x5565a221055c - core::fmt::write::h85b247e856e081ad
   2:     0x5565a21e8b75 - std::io::Write::write_fmt::he3b80a66fc2ba5d3
   3:     0x5565a21ef660 - std::panicking::default_hook::{{closure}}::hf2bcdea8e51c0c13
   4:     0x5565a21ef215 - std::panicking::default_hook::h8864cfaaed08e53a
   5:     0x5565a21efd14 - std::panicking::rust_panic_with_hook::hb272975096b9f3ce
   6:     0x5565a21ef7f0 - std::panicking::begin_panic_handler::{{closure}}::hbbd6c4e11858ba52
   7:     0x5565a21edf04 - std::sys_common::backtrace::__rust_end_short_backtrace::hdd56e8729123abc5
   8:     0x5565a21ef759 - rust_begin_unwind
   9:     0x5565a10eb9ab - std::panicking::begin_panic_fmt::hd76138c622de6537
  10:     0x5565a1511f7a - wgpu::backend::direct::Context::handle_error_fatal::ha0255c27d5a003d8
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.12.0/src/backend/direct.rs:214:9
  11:     0x5565a1513956 - <wgpu::backend::direct::Context as wgpu::Context>::surface_configure::h3a2c6b637f89e012
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.12.0/src/backend/direct.rs:921:13
  12:     0x5565a13e44cd - wgpu::Surface::configure::hddb44dc4040dac21
                               at /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.12.0/src/lib.rs:3267:9
  13:     0x5565a126d216 - <iced_wgpu::window::compositor::Compositor as iced_graphics::window::compositor::Compositor>::configure_surface::hb6dc9fb70020e12d
                               at /home/username/iced/wgpu/src/window/compositor.rs:124:9
  14:     0x5565a1208da9 - iced_winit::application::run_instance::{{closure}}::h38535696a18758eb
                               at /home/username/iced/winit/src/application.rs:245:5
  15:     0x5565a116fdbb - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h55bc52091ab264db
                               at /builddir/build/BUILD/rustc-1.57.0-src/library/core/src/future/mod.rs:80:19
  16:     0x5565a120c6e9 - iced_winit::application::run::{{closure}}::ha15e244e1e2462fc
                               at /home/username/iced/winit/src/application.rs:207:24
  17:     0x5565a1132f46 - winit::platform_impl::platform::wayland::event_loop::EventLoop<T>::run_return::hb9e9409dda5b0189
                               at /home/username/.cargo/git/checkouts/winit-57d3141eaf559308/02a1238/src/platform_impl/linux/wayland/event_loop/mod.rs:224:9
  18:     0x5565a120db76 - winit::platform_impl::platform::EventLoop<T>::run_return::had4dceb1328d6af2
                               at /home/username/.cargo/git/checkouts/winit-57d3141eaf559308/02a1238/src/platform_impl/linux/mod.rs:662:56
  19:     0x5565a118145d - <winit::event_loop::EventLoop<T> as winit::platform::run_return::EventLoopExtRunReturn>::run_return::ha46e60bc3e6928be
                               at /home/username/.cargo/git/checkouts/winit-57d3141eaf559308/02a1238/src/platform/run_return.rs:56:9
  20:     0x5565a120c162 - iced_winit::application::run::hbaac568e00b9bdb4
                               at /home/username/iced/winit/src/application.rs:182:5
  21:     0x5565a11393c2 - iced::application::Application::run::hba7f665a00a563fc
                               at /home/username/iced/src/application.rs:215:16
  22:     0x5565a118b720 - game_of_life::main::h4c77da4fa2ed6757
                               at /home/username/iced/examples/game_of_life/src/main.rs:21:5
  23:     0x5565a1194b52 - core::ops::function::FnOnce::call_once::hec6f89f8955262f4
                               at /builddir/build/BUILD/rustc-1.57.0-src/library/core/src/ops/function.rs:227:5
  24:     0x5565a1170aaa - std::sys_common::backtrace::__rust_begin_short_backtrace::h72d2d2bac68dbb65
                               at /builddir/build/BUILD/rustc-1.57.0-src/library/std/src/sys_common/backtrace.rs:123:18
  25:     0x5565a1109546 - std::rt::lang_start::{{closure}}::h3ff8839ceeba49e9
                               at /builddir/build/BUILD/rustc-1.57.0-src/library/std/src/rt.rs:146:18
  26:     0x5565a21ed71b - std::rt::lang_start_internal::hcbc5d1079a591413
  27:     0x5565a1109510 - std::rt::lang_start::hb54c7579084a2280
                               at /builddir/build/BUILD/rustc-1.57.0-src/library/std/src/rt.rs:145:17
  28:     0x5565a118d5bc - main
  29:     0x7ffb1d119560 - __libc_start_call_main
  30:     0x7ffb1d11960c - __libc_start_main@@GLIBC_2.34
  31:     0x5565a10ecd55 - _start

Note that this is for AMD Renoir iGPU

VarLad avatar Jan 15 '22 00:01 VarLad

@kvark I've tested this on an AMD GPU and it works The two places where it doesn't work on Wayland is, Intel (iGPU) + NVIDIA (discrete) and AMD (iGPU) + NVIDIA (discrete) Not sure if this issue only occurs for AMD/Intel (iGPU) + NVIDIA or all hybrid systems in general

Note that since basically all CPUs come with an iGPU these days, a lot of people have hybrid systems

VarLad avatar Jan 15 '22 01:01 VarLad

Looking at the logs, I'm beginning to think its more a winit issue than anything else

VarLad avatar Jan 15 '22 12:01 VarLad

After cargo update iced compiles for me on M1 OSX. cargo run --package game_of_life works. If started from within tmux no window opens.

ahcm avatar Jan 20 '22 08:01 ahcm

@hecrj Can you try making iced run with wgpu (master branch)?

I'm taking a guess that ithe issue has been resolved on master branch (of wgpu) and when I tried updating the dependency, I got a build error (in the game_of_life example)

VarLad avatar Jan 23 '22 23:01 VarLad

@VarLad We normally wait until a proper wgpu release, since there are also dependencies that need updating (e.g. wgpu_glyph).

Could you elaborate on what you are trying to do? Why do you guess it's resolved in master and what is your build error?

hecrj avatar Jan 24 '22 06:01 hecrj

@hecrj I found out that my issue is the same as https://github.com/gfx-rs/wgpu/issues/2301

Since it works for me on the master branch, I'm making the assumption that it was fixed in some PR. I changed the wgpu dependency in iced/wgpu/Cargo.toml to master branch via wgpu = { git = "https://github.com/gfx-rs/wgpu", branch = "master" }

Then I ran cargo update and ran

> cargo run --package game_of_life
   Compiling iced_wgpu v0.4.0 (/home/username/iced/wgpu)
error[E0308]: mismatched types
  --> wgpu/src/text.rs:55:24
   |
55 |                 .build(device, format);
   |                        ^^^^^^ expected struct `wgpu::Device`, found struct `Device`
   |
   = note: expected reference `&wgpu::Device`
              found reference `&Device`
   = note: perhaps two different versions of crate `wgpu` are being used?

error[E0308]: mismatched types
  --> wgpu/src/text.rs:55:32
   |
55 |                 .build(device, format);
   |                                ^^^^^^ expected enum `wgpu_types::TextureFormat`, found enum `TextureFormat`
   |
   = note: perhaps two different versions of crate `wgpu_types` are being used?

error[E0308]: mismatched types
  --> wgpu/src/text.rs:83:17
   |
83 |                 device,
   |                 ^^^^^^ expected struct `wgpu::Device`, found struct `Device`
   |
   = note: expected reference `&wgpu::Device`
              found reference `&Device`
   = note: perhaps two different versions of crate `wgpu` are being used?

error[E0308]: mismatched types
  --> wgpu/src/text.rs:84:17
   |
84 |                 staging_belt,
   |                 ^^^^^^^^^^^^ expected struct `wgpu::util::belt::StagingBelt`, found struct `StagingBelt`
   |
   = note: expected mutable reference `&mut wgpu::util::belt::StagingBelt`
              found mutable reference `&mut StagingBelt`
   = note: perhaps two different versions of crate `wgpu` are being used?

error[E0308]: mismatched types
  --> wgpu/src/text.rs:85:17
   |
85 |                 encoder,
   |                 ^^^^^^^ expected struct `wgpu::CommandEncoder`, found struct `CommandEncoder`
   |
   = note: expected mutable reference `&mut wgpu::CommandEncoder`
              found mutable reference `&mut CommandEncoder`
   = note: perhaps two different versions of crate `wgpu` are being used?

error[E0308]: mismatched types
  --> wgpu/src/text.rs:86:17
   |
86 |                 target,
   |                 ^^^^^^ expected struct `wgpu::TextureView`, found a different struct `wgpu::TextureView`
   |
   = note: expected reference `&wgpu::TextureView` (struct `wgpu::TextureView`)
              found reference `&wgpu::TextureView` (struct `wgpu::TextureView`)
   = note: perhaps two different versions of crate `wgpu` are being used?

For more information about this error, try `rustc --explain E0308`.
error: could not compile `iced_wgpu` due to 6 previous errors

VarLad avatar Jan 24 '22 15:01 VarLad

@VarLad if you want to test with the most recent wgpu try adding something like this to your top-level Cargo.toml

[patch.crates-io]
wgpu = { git = "https://github.com/gfx-rs/wgpu", branch = "master" }

I just tried and it did not fix the issue for me unfortunately :/

Initially I thought this problem was related to my NVIDIA prime setup. But it sounds like there is a bunch of people here with different configurations facing this issue.

kaimast avatar Feb 04 '22 23:02 kaimast

@kaimast Then I'm getting this error (if I run cargo run --package game_of_life)

     Running `target/debug/game_of_life`
[ERROR wgpu::backend::direct] Handling wgpu errors as fatal by default
thread 'main' panicked at 'wgpu error: Validation Error

Caused by:
    In Device::create_shader_module
      note: label = `Glyph Shader`

Shader 'Glyph Shader' parsing error: expected global item ('struct', 'let', 'var', 'type', ';', 'fn') or the end of the file, found '['
  ┌─ wgsl:5:1
  │
5 │ [[group(0), binding(0)]] var<uniform> globals: Globals;
  │ ^ expected global item ('struct', 'let', 'var', 'type', ';', 'fn') or the end of the file


    expected global item ('struct', 'let', 'var', 'type', ';', 'fn') or the end of the file, found '['

', /home/varlad/.cargo/git/checkouts/wgpu-53e70f8674b08dd4/3c3fbe8/wgpu/src/backend/direct.rs:2273:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@hecrj any idea?

VarLad avatar Feb 05 '22 06:02 VarLad

New wgpu expects more modern WGSL syntax, i.e. @group(0) @binding(0) instead of [[group(0), binding(0)]].

kvark avatar May 22 '22 15:05 kvark

@hecrj @kvark I think the main issue is because of Hybrid graphics. Do you remember the flags which I can use to specify that I want to use the RADV drivers from Mesa?

VarLad avatar Oct 17 '22 15:10 VarLad

I tried a bunch of flags, namely __NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=non_NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=mesa

I uninstalled my NVIDIA drivers and it worked fine. It breaks as soon as I install my NVIDIA drivers back. For context, its a Hybrid laptop with AMD CPU (+iGPU) + NVIDIA GPU This issue is only with Vulkan backend and OpenGL works fine. (although that has SVG issue so I can't use it)

VarLad avatar Oct 17 '22 16:10 VarLad

So I'm guessing, for the Vulkan backend, it has issues choosing the GPU?

VarLad avatar Oct 17 '22 16:10 VarLad

An update to this:

This was the fix for me: VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/radeon_icd.x86_64.json executable_name

VarLad avatar Oct 17 '22 16:10 VarLad