Wgpu: hello_triangle_c panics while unwrapping power preference

Created on 11 Mar 2019  路  8Comments  路  Source: gfx-rs/wgpu

Running hello_triangle_c causes the following error in on the rust side:

thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:345:21
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:70
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:58
             at src/libstd/panicking.rs:200
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:215
   4: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   5: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:385
   6: rust_begin_unwind
             at src/libstd/panicking.rs:312
   7: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
   8: core::panicking::panic
             at src/libcore/panicking.rs:49
   9: <core::option::Option<T>>::unwrap
             at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/libcore/macros.rs:10
  10: wgpu_native::instance::instance_get_adapter
             at wgpu-native/src/instance.rs:152
  11: wgpu_native::instance::instance_get_adapter
             at wgpu-native/src/instance.rs:161
  12: main
fatal runtime error: failed to initiate panic, error 5
Abort trap: 6

Steps to repro on macOS

git clone https://github.com/gfx-rs/wgpu.git
cd wgpu
cargo build 
# We now have target/debug/libwgpu_native.dylib

cd examples/hello_triangle_c
cmake .
make hello_triangle

export RUST_BACKTRACE=1
./hello_triangle_c

glfw 3.2.1
cmake 3.13.4
make 3.81
rust 1.33
macos 10.13.6
xcode 10.1

bug

Most helpful comment

Brilliant! The command from travis builds a binary that works on my machine.

Thanks so much for being so responsive on this. Now I can start experimenting against the C API.

All 8 comments

I can't confirm right now but I believe we don't assume any backend by default, so you'll need to specify cargo build --features metal or cargo build --features gfx-backend-metal depending on which crate you build.

We could probably provide an error when no backend has been selected.

I suspected it was something to do with selecting a backend. To clarify my understanding, is it correct to say that I've compiled wgpu with no backend, and then the C code calls correctly into the rust library which was compiled incorrectly?

I've just cloned a fresh copy of the repo and built with cargo build --features metal using the same repro steps above and am getting the same error.

In addition, running the following from the root of a fresh copy of the repo:

make lib-native
cd examples/hello_triangle_c/
cmake .
make hello_triangle
./hello_triangle

Results in a Segmentation fault: 11

I also don't see gfx-backend-metal in the features section of wgpu-native's Cargo.toml, which could explain why the conditional compilation of the metal backend is working for the rust example but not the C one.

To clarify my understanding, is it correct to say that I've compiled wgpu with no backend, and then the C code calls correctly into the rust library which was compiled incorrectly?

That's right, the library needs to be compiled with a particular backend specified (most functions will fail when they hit an unimplemented somewhere).

The Makefile is probably out of date because it existed before we switched to cmake for the C example.

I also don't see gfx-backend-metal in the features section of wgpu-native's Cargo.toml

I don't think this should be required because it's an optional crate (i.e. --features gfx-backend-metal should work).

You should be able to run the command (including all of the cds) we just added to Travis: https://github.com/gfx-rs/wgpu/blob/master/.travis.yml#L47 I also forgot to mention the local flag when building wgpu-native directly.

Edit: We also have a Gitter to chat if it's easier to discuss there.

Brilliant! The command from travis builds a binary that works on my machine.

Thanks so much for being so responsive on this. Now I can start experimenting against the C API.

@cshenton don't hesitate to visit us on gitter or elsewhere! We'd be happy to showcase your screenshots in the gallery.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Aeledfyr picture Aeledfyr  路  23Comments

lordnoriyuki picture lordnoriyuki  路  21Comments

zicklag picture zicklag  路  84Comments

z2oh picture z2oh  路  13Comments

m4b picture m4b  路  14Comments