From 14fc82f14294062a51dc7ef260610816a275b7b2 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Fri, 12 Jul 2024 15:06:16 +0200 Subject: [PATCH 1/4] attempt to reproduce a crash with a more complex example --- .../examples/multi_world_deletion3.rs | 145 ++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 bevy_rapier3d/examples/multi_world_deletion3.rs diff --git a/bevy_rapier3d/examples/multi_world_deletion3.rs b/bevy_rapier3d/examples/multi_world_deletion3.rs new file mode 100644 index 00000000..6b455d80 --- /dev/null +++ b/bevy_rapier3d/examples/multi_world_deletion3.rs @@ -0,0 +1,145 @@ +use bevy::{input::common_conditions::input_just_pressed, prelude::*}; +use bevy_rapier3d::prelude::*; + +const N_WORLDS: usize = 2; + +fn main() { + App::new() + .insert_resource(ClearColor(Color::srgb( + 0xF9 as f32 / 255.0, + 0xF9 as f32 / 255.0, + 0xFF as f32 / 255.0, + ))) + .insert_resource(TimestepMode::Interpolated { + dt: 1f32 / 60f32, + time_scale: 1f32, + substeps: 4, + }) + .add_plugins(( + DefaultPlugins, + RapierPhysicsPlugin::::default() + .with_default_world(RapierContextInitialization::NoAutomaticRapierContext), + RapierDebugRenderPlugin::default(), + )) + .add_systems( + Startup, + ((create_worlds, setup_physics).chain(), setup_graphics), + ) + .add_systems(Update, move_platforms) + .add_systems(PostUpdate, remove_entities_colliding) + .add_systems( + Update, + change_world.run_if(input_just_pressed(KeyCode::KeyC)), + ) + .run(); +} + +fn create_worlds(mut commands: Commands) { + for i in 0..N_WORLDS { + let mut world = commands.spawn((RapierContext::default(), WorldId(i))); + if i == 0 { + world.insert(DefaultRapierContext); + } + } +} + +fn setup_graphics(mut commands: Commands) { + commands.spawn(Camera3dBundle { + transform: Transform::from_xyz(0.0, 3.0, -10.0) + .looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), + ..Default::default() + }); +} + +#[derive(Component)] +pub struct WorldId(pub usize); + +#[derive(Component)] +struct Platform { + starting_y: f32, +} + +fn move_platforms(time: Res