Skip to content

Crash on macOS, related to ExtendedMaterial and custom vertex buffer layout #16588

Open
@splashdust

Description

@splashdust

Bevy version

0.15

[Optional] Relevant system information

Rust version: 1.83

SystemInfo { os: "MacOS 15.1.1 ", kernel: "24.1.0", cpu: "Apple M1 Max", core_count: "10", memory: "64.0 GiB" }
AdapterInfo { name: "Apple M1 Max", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }

Problem

Since updating to Bevy 0.15, my plugin no longer runs on macOS. The plugin is using ExtendedMaterial with a custom shader and one extra vertex attribute.

The application crashes immediately on startup with the following error:

thread 'Compute Task Pool (0)' panicked at /Users/joacim/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-23.0.1/src/backend/wgpu_core.rs:1102:18:
wgpu error: Validation Error

Caused by:
  In Device::create_render_pipeline, label = 'pbr_prepass_pipeline'
    Internal error in ShaderStages(VERTEX) shader: Metal: program_source:252:14: error:  from vector 'metal::float3' (aka 'float3') to vector 'metal::float2' (aka 'float2') of different size
        uv = metal::float2(unpackFloat32x3_(vb_15_elem.data[12], vb_15_elem.data[13], vb_15_elem.data[14], vb_15_elem.data[15], vb_15_elem.data[16], vb_15_elem.data[17], vb_15_elem.data[18], vb_15_elem.data[19], vb_15_elem.data[20], vb_15_elem.data[21], vb_15_elem.data[22], vb_15_elem.data[23]));
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_render::render_resource::pipeline_cache::PipelineCache::process_pipeline_queue_system`!
thread '<unnamed>' panicked at /Users/joacim/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_render-0.15.0/src/render_resource/pipeline_cache.rs:546:28:
index out of bounds: the len is 0 but the index is 6
Encountered a panic in system `bevy_render::renderer::render_system`!

It looks like some UVs are being supplied to the shader as vec3 instead of vec2, and I can't figure out why. When the mesh is created, I'm only inserting [f32; 2] UV entries.

Other than that, I haven't been able to isolate the problem, but it goes away if I just remove the UV data from the mesh and buffer layout. Also, it seems to be related to ExtendedMaterial, because using a different material with the same meshes and layout works, so I think the issue is happening in the pbr pipeline.

It's possible that the error is somewhere in my code, but the fact that it only happens on macOS (with metal backend) causes me to suspect that it's an upstream issue. I was not able to reproduce the issue in Bevys extended_material example though, so it's likely being caused by some combination of things.

Additional information

The issue can be reproduced by running the noise_terrain example (or any example except custom_material) in https://github.com/splashdust/bevy_voxel_world

The custom_material example does not use ExtendedMaterial and does not cause the error to happen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behaviorO-MacOSSpecific to the MacOS (Apple) desktop operating systemO-iOSSpecific to the iOS mobile operating systemS-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions