Open rparrett opened 2 days ago
I ran your code on my Windows computer and a panic also occurred. However, it was due to another reason, which is as follows.
thread 'Compute Task Pool (7)' panicked at C:\Users\decli\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_render-0.15.0-rc.3\src\mesh\allocator.rs:656:48:
attempt to divide by zero
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_render::mesh::allocator::allocate_and_free_meshes`!
Besides, this panic only occurs in version 0.15.0-rc.3.
This new mesh allocator panic seems to be from me minimizing the repro excessively. The initial panic I experienced happens when there are some vertex attributes/indices, but they are empty vecs. This new panic happens when there are no vertex attributes or indices at all.
I did some additional testing of both scenarios on mac and windows, and edited the PR description with both code snippets I'm using to create the meshes.
platform | mesh attributes | result |
---|---|---|
win/nvidia/webgl2/chrome | No | Panic (bevy mesh allocator) |
win/nvidia/webgl2/chrome | Yes | OK |
win/nvidia/native | No | Panic (bevy mesh allocator) |
win/nvidia/native | Yes | OK |
m1/webgl2/chrome | No | Panic (wgpu buffer) |
m1/webgl2/chrome | Yes | Panic (wgpu buffer) |
m1/native | No | Panic (bevy mesh allocator) |
m1/native | Yes | OK |
Both of these scenarios did not panic in 0.14.2.
Is this a regression? Should it block 0.15?
This is a regression and I don't think we should panic in either case.
Some considerations:
IMO, this shouldn't block 0.15.
Bevy version
0.15.0-rc.3
Relevant system information
AdapterInfo { name: "ANGLE (Apple, ANGLE Metal Renderer: Apple M1 Max, Unspecified Version)", vendor: 4203, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "WebGL 2.0 (OpenGL ES 3.0 Chromium)", backend: Gl }
What you did
I experienced this panic in the wild while migrating an app that uses a lot of
Mesh2d
by way ofbevy_prototype_lyon
. It seems that the root cause is creating aLine
with zero length in that plugin.Minimal repro for Bevy 0.15
```rust use bevy::{asset::RenderAssetUsages, prelude::*, render::mesh::PrimitiveTopology}; fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .run(); } fn setup( mut commands: Commands, mut meshes: ResMutBevy 0.14 code tested
```rust use bevy::{ prelude::*, render::{mesh::PrimitiveTopology, render_asset::RenderAssetUsages}, sprite::{MaterialMesh2dBundle, Mesh2dHandle}, }; fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .run(); } fn setup( mut commands: Commands, mut meshes: ResMutThe exact type of mesh generated by a zero-length line w/
```rust let mesh = Mesh::new( PrimitiveTopology::TriangleList, RenderAssetUsages::default(), ) .with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, Vec::<[f32; 3]>::new()) .with_inserted_attribute(Mesh::ATTRIBUTE_COLOR, Vec::<[f32; 4]>::new()) .with_inserted_indices(Indices::U32(vec![])); ```bevy_prototype_lyon
(same panic)What went wrong
Additional information
This is a silly thing to be trying to do, but it did not panic in Bevy 0.14.
Possibly related to https://github.com/gfx-rs/wgpu/issues/3170#issuecomment-2491549161
webgpu
and native on m1 mac seem to work okay.