AryanpurTech / BlueEngine

Blue Engine is a general-purpose and easy-to-use graphics engine written in rust.
Apache License 2.0
341 stars 16 forks source link

Hello World crashes #77

Closed pi314ever closed 2 months ago

pi314ever commented 2 months ago

Describe the bug The Hello World provided in the README crashes

thread 'main' panicked at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-22.1.0/src/backend/wgpu_core.rs:786:18:
Error in Surface::configure: Validation Error

Caused by:
  Requested format Rgba8UnormSrgb is not in list of supported formats: [Bgra8Unorm, Bgra8UnormSrgb]

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

To Reproduce Steps to reproduce the behavior:

  1. Make a new project
  2. Replace main.rs with the provided code in README
  3. cargo run

Expected behavior No crash and a valid hello world example

Screenshots N/A

Desktop (please complete the following information):

Smartphone (please complete the following information): N/A

Additional context Add any other context about the problem here.

ElhamAryanpur commented 2 months ago

are you sure?

image

any errors?

suprohub commented 2 months ago

Hello world works on other versions?

pi314ever commented 2 months ago

I'm not sure why it's failing for me, here's the full stacktrace:

RUST_BACKTRACE=full cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
     Running `target/debug/adaptive-learning-pendulum`
thread 'main' panicked at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-22.1.0/src/backend/wgpu_core.rs:786:18:
Error in Surface::configure: Validation Error

Caused by:
  Requested format Rgba8UnormSrgb is not in list of supported formats: [Bgra8Unorm, Bgra8UnormSrgb]

stack backtrace:
   0:     0x6247f8dbafa5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h74a0a1c6c79303b9
   1:     0x6247f8de473b - core::fmt::write::ha98c8e7f53d35324
   2:     0x6247f8db7fbf - std::io::Write::write_fmt::h17471482d4c75b07
   3:     0x6247f8dbad7e - std::sys_common::backtrace::print::h2f8442a89abef5a1
   4:     0x6247f8dbc2c9 - std::panicking::default_hook::{{closure}}::h0a8149426a26b8c7
   5:     0x6247f8dbc06a - std::panicking::default_hook::hc20f00843fe57152
   6:     0x6247f8dbc763 - std::panicking::rust_panic_with_hook::h26ced991d9155f68
   7:     0x6247f8dbc644 - std::panicking::begin_panic_handler::{{closure}}::h07fc4ac35801b8ab
   8:     0x6247f8dbb469 - std::sys_common::backtrace::__rust_end_short_backtrace::h4418527efe301050
   9:     0x6247f8dbc377 - rust_begin_unwind
  10:     0x6247f75ed003 - core::panicking::panic_fmt::h6d21d242c9051253
  11:     0x6247f7f907f0 - wgpu::backend::wgpu_core::ContextWgpuCore::handle_error_fatal::hea4152d09c7948e4
                               at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-22.1.0/src/backend/wgpu_core.rs:317:9
  12:     0x6247f7f951c3 - <wgpu::backend::wgpu_core::ContextWgpuCore as wgpu::context::Context>::surface_configure::h14c9788aee34f6fc
                               at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-22.1.0/src/backend/wgpu_core.rs:786:13
  13:     0x6247f7fb9d8a - <T as wgpu::context::DynContext>::surface_configure::h5ab0fe129ea2739f
                               at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-22.1.0/src/context.rs:2169:9
  14:     0x6247f8070160 - wgpu::Surface::configure::h9c246a74ccecca85
                               at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-22.1.0/src/lib.rs:5658:9
  15:     0x6247f76a62bb - blue_engine::window::<impl winit::application::ApplicationHandler for blue_engine::header::Engine>::resumed::h61d4f18fc313e229
                               at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/blue_engine-0.5.17/src/window.rs:164:17
  16:     0x6247f7604046 - winit::event_loop::dispatch_event_for_app::hd43b75d26cec0860
                               at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/event_loop.rs:646:27
  17:     0x6247f7604046 - winit::event_loop::EventLoop<T>::run_app::{{closure}}::h58daef7ebd8f6327
                               at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/event_loop.rs:265:49
  18:     0x6247f7603daf - core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut::h71d01423e75834e8
                               at /usr/src/debug/rust/rustc-1.80.1-src/library/core/src/ops/function.rs:294:13
  19:     0x6247f764b9fa - winit::platform_impl::linux::x11::EventLoop<T>::single_iteration::h4d4e355ac0ce10d7
                               at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/platform_impl/linux/x11/mod.rs:516:13
  20:     0x6247f764ad46 - winit::platform_impl::linux::x11::EventLoop<T>::pump_events::h4db19ddd63dd1e88
                               at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/platform_impl/linux/x11/mod.rs:418:13
  21:     0x6247f764b5cc - winit::platform_impl::linux::x11::EventLoop<T>::run_on_demand::h0072b9a5859fecb8
                               at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/platform_impl/linux/x11/mod.rs:385:19
  22:     0x6247f7612866 - winit::platform_impl::linux::EventLoop<T>::run_on_demand::h1a2bb85c61e3af1c
                               at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/platform_impl/linux/mod.rs:813:56
  23:     0x6247f761311a - winit::platform_impl::linux::EventLoop<T>::run::h19ddb62f2d8bdb65
                               at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/platform_impl/linux/mod.rs:806:9
  24:     0x6247f7603eb1 - winit::event_loop::EventLoop<T>::run_app::hcc7a46d5feec9f9e
                               at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.30.5/src/event_loop.rs:265:9
  25:     0x6247f7652545 - blue_engine::window::<impl blue_engine::header::Engine>::update_loop::hf05cced57d572042
                               at /home/daniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/blue_engine-0.5.17/src/window.rs:143:9
  26:     0x6247f762b896 - adaptive_learning_pendulum::main::h73989028b8c666df
                               at /data/personal-projects/adaptive-learning-pendulum/simulation/src/main.rs:20:5
  27:     0x6247f7614b7b - core::ops::function::FnOnce::call_once::h02837da30f996126
                               at /usr/src/debug/rust/rustc-1.80.1-src/library/core/src/ops/function.rs:250:5
  28:     0x6247f76021ae - std::sys_common::backtrace::__rust_begin_short_backtrace::hcad38e5c569d33c2
                               at /usr/src/debug/rust/rustc-1.80.1-src/library/std/src/sys_common/backtrace.rs:155:18
  29:     0x6247f76132c1 - std::rt::lang_start::{{closure}}::he536e5c0655aa947
                               at /usr/src/debug/rust/rustc-1.80.1-src/library/std/src/rt.rs:159:18
  30:     0x6247f8daecdd - std::rt::lang_start_internal::hc6d1267ee67d84b1
  31:     0x6247f761329a - std::rt::lang_start::h2cc9f039d727e120
                               at /usr/src/debug/rust/rustc-1.80.1-src/library/std/src/rt.rs:158:17
  32:     0x6247f762b90e - main
  33:     0x753b02071e08 - <unknown>
  34:     0x753b02071ecc - __libc_start_main
  35:     0x6247f75edb95 - _start
  36:                0x0 - <unknown>
ElhamAryanpur commented 2 months ago

oh I see, the error makes sense now

ElhamAryanpur commented 2 months ago

this indeed is a bug

ElhamAryanpur commented 2 months ago

@pi314ever Can you try the #79 ?

add this to your Cargo.toml:

blue_engine = { git = "https://github.com/AryanpurTech/BlueEngine/", rev = "a1fa71ba6dca6eba3a1f54301261f99129850e55" }

instead of your previous dependency. Let me know if it still crashes.

pi314ever commented 2 months ago

@ElhamAryanpur that works! Thanks. Just curious, do you know what was missing/wrong?

ElhamAryanpur commented 2 months ago

Awesome @pi314ever !

As the error stated, it was the unsupported texture format. Most platforms support either Srgba8Unorm or Rgba8Unorm. On Android for example it's the latter. These are just the color format of textures in which the format is specified when a surface is given (a context to render to be given by the OS).

Now on winit 0.30 which is the window provider library we use, the surface was no longer given before the update loop. Not even the window is initialized anymore before the update loop... Hence the texture format was not specified and by default it went to Rgba8Unorm. Which is what your machine didn't support.

What I did instead was revert the default to Srgba8Unorm for desktop and Rgba8Unorm for Android, and then as soon as window is initialized configure everything again with the correct provided texture format instead of defaults. Which I think is what solved the issue.

I'm glad it's working now, will merge it and publish a version tomorrow.