bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.15k stars 3.46k forks source link

Crash when loading a gltf model. #6710

Closed AllenDang closed 1 year ago

AllenDang commented 1 year ago

Bevy version

0.9.0

What you did

Spawn a scene from a glb file and bevy crashed.

Error message is

❯ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.27s
     Running `target/debug/model_explorer`
2022-11-21T10:54:26.688105Z  INFO bevy_render::renderer: AdapterInfo { name: "Apple M1 Max", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }
2022-11-21T10:54:29.985476Z  INFO model_explorer: loading...
2022-11-21T10:54:30.241790Z ERROR wgpu::backend::direct: Handling wgpu errors as fatal by default    
thread 'Compute Task Pool (3)' panicked at 'wgpu error: Validation Error

Caused by:
    In Device::create_bind_group
    texture binding 9 expects sample type = Float { filterable: true }, but given a view with format = Rgba16Uint

', /Users/allen/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.14.0/src/backend/direct.rs:2403:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'task has failed', /Users/allen/.cargo/registry/src/github.com-1ecc6299db9ec823/async-task-4.3.0/src/task.rs:426:43

It could be rendered normally via gltf viewer.

image

Here is the glb file leads to the crash. PIPIXIA.glb.zip

AllenDang commented 1 year ago

@nicopap I know the core dev of bevy may not have time to fix it now, I'm wondering if you or anyone could give me a hint about where should I start to look at, I could start fixing this and contribute a PR.

nicopap commented 1 year ago

It looks like the texture format is the culprit here, try saving the model textures in a different format

AllenDang commented 1 year ago

@nicopap This model could be normally imported and rendered in various engines including Godot/Unreal/Unity/Raylib, so I'm thinking about to fix the compatibility of bevy.

nicopap commented 1 year ago

I'm not sure what is causing this. I think you might some luck looking at the code that the following PR changed https://github.com/bevyengine/bevy/pull/5527

Otherwise, it would be in the GLTF loader (bevy_gltf/src/loader.rs iirc) you'd need to make sure the image data is properly handled when the GLTF is loaded.

mockersf commented 1 year ago

One of the texture in the glb file is in a format not expected by Bevy. If I manually convert it to another format, it renders:

Screenshot 2022-12-01 at 18 51 08

Short term, you can use the converted glb file here: PIPIXIA-converted.glb.zip (I'm not very good at image conversion, so I also compressed it. I didn't notice any worse quality)

Longer term, Bevy could convert the texture when loading the glb file to a supported format

AllenDang commented 1 year ago

@mockersf Can you tell me which texture causes this issue?

mockersf commented 1 year ago

I think it was the normals

AllenDang commented 1 year ago

@mockersf Thanks, I'll see what I can do there.

nicopap commented 1 year ago

Should be fixed by #9611