Open
Description
Bevy version
0.16.1
If your bug is rendering-related, copy the adapter info that appears when you run Bevy.
`AdapterInfo { name: "NVIDIA GeForce RTX 3060", vendor: 4318, device: 9476, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "572.83", backend: Vulkan }`
What you did
I was attempting to dynamically create a mesh at runtime.
What went wrong
I received the following error at startup
2025-06-17T22:03:10.171264Z INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 10 Home", kernel: "19045", cpu: "AMD Ryzen 7 3700X 8-Core Processor", core_count: "8", memory: "31.9 GiB" }
2025-06-17T22:03:10.574933Z INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce RTX 3060", vendor: 4318, device: 9476, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "572.83", backend: Vulkan }
2025-06-17T22:03:10.778070Z INFO bevy_render::batching::gpu_preprocessing: GPU preprocessing is fully supported on this device.
2025-06-17T22:03:10.794753Z INFO bevy_winit::system: Creating new window App (0v1)
thread 'Compute Task Pool (7)' panicked at C:\Users\kerstop\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\bevy_render-0.16.1\src\mesh\allocator.rs:687:48:
attempt to divide by zero
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/5e16c662062fd6dee91f0fe2a1580483488d80cf/library\std\src\panicking.rs:697
1: core::panicking::panic_fmt
at /rustc/5e16c662062fd6dee91f0fe2a1580483488d80cf/library\core\src\panicking.rs:75
2: core::panicking::panic_const::panic_const_div_by_zero
at /rustc/5e16c662062fd6dee91f0fe2a1580483488d80cf/library\core\src\panicking.rs:175
3: core::num::impl$9::div_ceil
at C:\Users\kerstop\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\num\uint_macros.rs:3248
4: bevy_render::mesh::allocator::MeshAllocator::allocate
at C:\Users\kerstop\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\bevy_render-0.16.1\src\mesh\allocator.rs:687
5: bevy_render::mesh::allocator::MeshAllocator::allocate_meshes
at C:\Users\kerstop\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\bevy_render-0.16.1\src\mesh\allocator.rs:451
6: bevy_render::mesh::allocator::allocate_and_free_meshes
at C:\Users\kerstop\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\bevy_render-0.16.1\src\mesh\allocator.rs:365
7: core::ops::function::FnMut::call_mut
at C:\Users\kerstop\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:166
8: core::ops::function::impls::impl$3::call_mut
at C:\Users\kerstop\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:294
9: bevy_ecs::system::function_system::impl$39::run::call_inner
at C:\Users\kerstop\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\bevy_ecs-0.16.1\src\system\function_system.rs:945
10: bevy_ecs::system::function_system::impl$39::run
at C:\Users\kerstop\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\bevy_ecs-0.16.1\src\system\function_system.rs:948
11: bevy_ecs::system::function_system::impl$7::run_unsafe
at C:\Users\kerstop\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\bevy_ecs-0.16.1\src\system\function_system.rs:735
12: bevy_ecs::system::schedule_system::impl$1::run_unsafe<bevy_ecs::system::function_system::FunctionSystem<void (*)(bevy_ecs::change_detection::ResMut<bevy_render::mesh::allocator::MeshAllocator>,bevy_ecs::change_detection::Res<bevy_
render::mesh::allocator::M
at C:\Users\kerstop\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\bevy_ecs-0.16.1\src\system\schedule_system.rs:68
13: core::hint::black_box
at C:\Users\kerstop\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\hint.rs:482
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Encountered a panic in system `bevy_render::mesh::allocator::allocate_and_free_meshes`!
Additional information
With the help of the discord I was able to determine that the issues was not initializing the vertex attribute of the mesh when creating it. However this is not clear from the error message provided of "divide by zero".
The following seems to be able to reproduce the issue and commented section is how to resolve it.
fn reproduce(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
commands.spawn(Mesh3d(meshes.add(
Mesh::new(
render_resource::PrimitiveTopology::TriangleList,
RenderAssetUsages::all(),
), //.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, Vec::<Vec3>::new()),
)));
}
When I ran across this issue I had no way of telling what was wrong with my code or how to resolve it and feel that it would be helpful to have a more meaningful error message in this situation.