-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow shapes to be constructed with zero values #13365
Allow shapes to be constructed with zero values #13365
Conversation
Thanks for the pull request. I opened that issue, but it took me a while to investigate. It should be sufficient to fix
Only Edit: |
@mamekoro I couldn't get |
I tested on the latest main branch. cargo new circle
cd circle
git clone --depth=1 https://github.com/bevyengine/bevy
cargo add --path bevy
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, startup)
.run();
}
fn startup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands.spawn(Camera2dBundle::default());
commands.spawn(ColorMesh2dBundle {
mesh: meshes.add(Circle::new(0.0)).into(),
material: materials.add(Color::WHITE),
..default()
});
} The crash log is here;
full testIt is difficult to tell which shape has panicked when testing multiple shapes at once, so toggle comments to select only one shape to test. use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, test2d)
//.add_systems(Startup, test3d)
.run();
}
fn test2d(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands.spawn(Camera2dBundle::default());
// panics
commands.spawn(ColorMesh2dBundle {
mesh: meshes.add(Circle::new(0.0)).into(),
material: materials.add(Color::WHITE),
..default()
});
// no panic
//commands.spawn(ColorMesh2dBundle {
// mesh: meshes.add(Ellipse::new(0.0, 0.0)).into(),
// material: materials.add(Color::WHITE),
// ..default()
//});
// no panic
//commands.spawn(ColorMesh2dBundle {
// mesh: meshes.add(Annulus::new(0.0, 0.0)).into(),
// material: materials.add(Color::WHITE),
// ..default()
//});
// no panic
//commands.spawn(ColorMesh2dBundle {
// mesh: meshes
// .add(Triangle2d::new(Vec2::ZERO, Vec2::ZERO, Vec2::ZERO))
// .into(),
// material: materials.add(Color::WHITE),
// ..default()
//});
// no panic
//commands.spawn(ColorMesh2dBundle {
// mesh: meshes.add(Rectangle::new(0.0, 0.0)).into(),
// material: materials.add(Color::WHITE),
// ..default()
//});
// panics
//commands.spawn(ColorMesh2dBundle {
// mesh: meshes.add(RegularPolygon::new(0.0, 3)).into(),
// material: materials.add(Color::WHITE),
// ..default()
//});
// no panic
//commands.spawn(ColorMesh2dBundle {
// mesh: meshes.add(Capsule2d::new(0.0, 0.0)).into(),
// material: materials.add(Color::WHITE),
// ..default()
//});
}
fn test3d(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 5.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn(PointLightBundle {
point_light: PointLight {
shadows_enabled: true,
intensity: 10_000_000.,
range: 100.0,
..default()
},
transform: Transform::from_xyz(5.0, 10.0, 5.0),
..default()
});
// no panic
//commands.spawn(PbrBundle {
// mesh: meshes.add(Capsule3d::new(0.0, 0.0)),
// material: materials.add(StandardMaterial::default()).clone(),
// ..default()
//});
// no panic
//commands.spawn(PbrBundle {
// mesh: meshes.add(Cone {
// radius: 0.0,
// height: 0.0,
// }),
// material: materials.add(StandardMaterial::default()).clone(),
// ..default()
//});
// no panic
//commands.spawn(PbrBundle {
// mesh: meshes.add(Cuboid {
// half_size: Vec3::ZERO,
// }),
// material: materials.add(StandardMaterial::default()).clone(),
// ..default()
//});
// no panic
//commands.spawn(PbrBundle {
// mesh: meshes.add(Cylinder::new(0.0, 0.0)),
// material: materials.add(StandardMaterial::default()).clone(),
// ..default()
//});
// no panic (Tested with a non-zero normal vector)
//commands.spawn(PbrBundle {
// mesh: meshes.add(Plane3d::new(Vec3::new(0.0, 1.0, 0.0), Vec2::ZERO)),
// material: materials.add(StandardMaterial::default()).clone(),
// ..default()
//});
// no panic
//commands.spawn(PbrBundle {
// mesh: meshes.add(Sphere::new(0.0)),
// material: materials.add(StandardMaterial::default()).clone(),
// ..default()
//});
//commands.spawn(PbrBundle {
// mesh: meshes.add(Sphere::new(0.0).mesh().ico(4).unwrap()),
// material: materials.add(StandardMaterial::default()).clone(),
// ..default()
//});
//commands.spawn(PbrBundle {
// mesh: meshes.add(Sphere::new(0.0).mesh().uv(4, 4)),
// material: materials.add(StandardMaterial::default()).clone(),
// ..default()
//});
// no panic
//commands.spawn(PbrBundle {
// mesh: meshes.add(Torus::new(0.0, 0.0)),
// material: materials.add(StandardMaterial::default()).clone(),
// ..default()
//});
// no panic
//commands.spawn(PbrBundle {
// mesh: meshes.add(Triangle3d::new(Vec3::ZERO, Vec3::ZERO, Vec3::ZERO)),
// material: materials.add(StandardMaterial::default()).clone(),
// ..default()
//});
} |
@mamekoro I just ran your test against my changes and they seem to solve the issue. Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, although I agree with mockersf's suggestion
Co-authored-by: François Mockers <francois.mockers@vleue.com>
Should we reject |
I would allow it: it should behave fine. |
Objective
Fixes #13332.
Solution
The assertion
circumradius >= 0.0
to allow zero.Are there any other shapes that need to be allowed to be constructed with zero?