Skip to content

joints example bug reproduction + a 'fix' in userspace#536

Closed
ThierryBerger wants to merge 1 commit into
dimforge:masterfrom
ThierryBerger:joint_regression_investigation
Closed

joints example bug reproduction + a 'fix' in userspace#536
ThierryBerger wants to merge 1 commit into
dimforge:masterfrom
ThierryBerger:joint_regression_investigation

Conversation

@ThierryBerger
Copy link
Copy Markdown
Contributor

@ThierryBerger ThierryBerger commented Jun 19, 2024

code for investigation on #535.

What I did in this PR:

  • reduced the reproduction to 2 rigidbodies (1 fixed, 1 dynamic) + 1 revolute joint
  • run the app more slowly (through app.update()), code is in comments.
  • I noticed that adding the physics setup after the first update resulted in a valid state.
    • it actually results in a valid state most of the time, which is characteristic of a system update ambiguity.

My hypotheses:

  • rigidbodies are sleeping by default, so they are not moving, I'll test that by waking all entities continuously.
    • to be noted the rigidbodies are propagated the frame after (or probably somewhere in lateupdate)
    • 🔴 waking the rigidbodies continuously doesn't seem to help much.
  • an event or component added is not detected. that would be suprising given the diff from Update to Rapier 0.20 #525 but 🤷 (I would be less surprised if that bug arose due to bevy update, which is not the case here.)
    • 🟠 as I can see them in rapierContext.bodies, I think that's not the case, but we shouldn't rule out an inconsistent RapierContext state.
    • 🔍 The investigation for an inconsistant RapierContext state led to realize the NaN translation/rotation arrive during the simulation, a call to rapier function. So either it's a bug from rapier, or the state calling of the rapier context is invalid somehow. Either way, debugging this is overwhelming and resolution for that would benefit including a debugging helper (error messages, CI, examples...).
    • 🟢 delta_time being 0 is the cause for NaN values 🎉 !
  • a system order ambiguity seems a good place to look
    • 🟠 my investigation didn't lead to meaningful improvements when fixing system ordering, It might be part of the problem, but definitely not the only cause.

investigation for inconsistent rapier state

the dynamic body is getting NaN translation/rotation after the first simulation run:

🟢 The deltatime of integration_parameters being 0 is causing the simulation to return the NaN values. If I force set it to 0.0000001 before the first simulation, the behaviour works as expected 🎉 !

Now for the proper fix, we have several options:

  • do not step if delta time is 0 ? I'm not sure about the implications
  • force a minimum deltatime ? This could lead to surprising simulations 👎
  • order the systems to make the first simulation once delta_time is updated. I'm doubtful it's even possible, or that might lead to similar problem if the timescale is 0 ?
  • investigate why a delta_time of 0 leads to NaN values and fix that. 🔍 Currently investigating.

Opened dimforge/rapier#660 to fix that within rapier.

investigation on system order ambiguities

Helpful to get a feeling about current ambiguities: ThierryBerger#21

Current ambiguities reported by bevy detection:

2024-06-20T08:07:28.639475Z  WARN bevy_ecs::schedule::schedule: Schedule PostUpdate has ambiguities.
43 pairs of systems with conflicting data access have indeterminate execution order. Consider adding `before`, `after`, or `ambiguous_with` relationships between these:
 -- add_clusters (in set AddClusters) and camera_system<PerspectiveProjection> (in set CameraUpdateSystem)
    conflict on: ["bevy_render::camera::camera::Camera"]
 -- add_clusters (in set AddClusters) and camera_system<OrthographicProjection> (in set CameraUpdateSystem)
    conflict on: ["bevy_render::camera::camera::Camera"]
 -- add_clusters (in set AddClusters) and camera_system<Projection> (in set CameraUpdateSystem)
    conflict on: ["bevy_render::camera::camera::Camera"]
 -- no_automatic_morph_batching and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- no_automatic_skin_batching and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- compute_slices_on_sprite_change (in set ComputeSlices) and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- compute_slices_on_asset_event (in set ComputeSlices) and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- check_msaa and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- inherit_weights and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- reset_view_visibility (in set VisibilityPropagate) and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- setup_physics and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- visibility_propagate_system (in set VisibilityPropagate) and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- insert_deferred_lighting_pass_id_component and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- sync_removals and update_character_controls (in set SyncBackend)
    conflict on: ["bevy_rapier2d::plugin::context::RapierContext"]
 -- sync_removals and init_rigid_bodies (in set SyncBackend)
    conflict on: ["bevy_rapier2d::plugin::context::RapierContext"]
 -- sync_removals and init_colliders (in set SyncBackend)
    conflict on: ["bevy_rapier2d::plugin::context::RapierContext"]
 -- sync_removals and init_joints (in set SyncBackend)
    conflict on: ["bevy_rapier2d::plugin::context::RapierContext"]
 -- sync_removals and sync_removals (in set SyncBackend)
    conflict on: ["bevy_rapier2d::plugin::context::RapierContext", "bevy_ecs::event::Events<bevy_rapier2d::dynamics::rigid_body::MassModifiedEvent>"]
 -- sync_removals and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- sync_removals and apply_collider_user_changes (in set SyncBackend)
    conflict on: ["bevy_rapier2d::plugin::context::RapierContext", "bevy_ecs::event::Events<bevy_rapier2d::dynamics::rigid_body::MassModifiedEvent>"]
 -- sync_removals and apply_rigid_body_user_changes (in set SyncBackend)
    conflict on: ["bevy_rapier2d::plugin::context::RapierContext", "bevy_ecs::event::Events<bevy_rapier2d::dynamics::rigid_body::MassModifiedEvent>"]
 -- sync_removals and apply_joint_user_changes (in set SyncBackend)
    conflict on: ["bevy_rapier2d::plugin::context::RapierContext"]
 -- sync_removals and apply_initial_rigid_body_impulses (in set SyncBackend)
    conflict on: ["bevy_rapier2d::plugin::context::RapierContext"]
 -- sync_removals and step_simulation<()> (in set StepSimulation)
    conflict on: ["bevy_rapier2d::plugin::context::RapierContext"]
 -- sync_removals and writeback_rigid_bodies (in set Writeback)
    conflict on: ["bevy_rapier2d::plugin::context::RapierContext"]
 -- sync_removals and writeback_mass_properties (in set Writeback)
    conflict on: ["bevy_rapier2d::plugin::context::RapierContext", "bevy_ecs::event::Events<bevy_rapier2d::dynamics::rigid_body::MassModifiedEvent>"]
 -- sync_removals and event_update_system<MassModifiedEvent> (in set Writeback)
    conflict on: ["bevy_ecs::event::Events<bevy_rapier2d::dynamics::rigid_body::MassModifiedEvent>"]
 -- sync_removals and debug_render_scene
    conflict on: ["bevy_rapier2d::plugin::context::RapierContext"]
 -- camera_system<PerspectiveProjection> (in set CameraUpdateSystem) and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- camera_system<PerspectiveProjection> (in set CameraUpdateSystem) and process_output_system (in set ProcessOutput)
    conflict on: ["bevy_window::window::Window"]
 -- camera_system<OrthographicProjection> (in set CameraUpdateSystem) and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- camera_system<OrthographicProjection> (in set CameraUpdateSystem) and process_output_system (in set ProcessOutput)
    conflict on: ["bevy_window::window::Window"]
 -- camera_system<Projection> (in set CameraUpdateSystem) and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- camera_system<Projection> (in set CameraUpdateSystem) and process_output_system (in set ProcessOutput)
    conflict on: ["bevy_window::window::Window"]
 -- window_closed (in set Update) and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- update_accessibility_nodes (in set Update) and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- update_accessibility_nodes (in set Update) and process_output_system (in set ProcessOutput)
    conflict on: ["bevy_window::window::Window"]
 -- poll_receivers (in set Update) and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- exit_on_all_closed and apply_deferred (in set SyncBackend)
    conflict on: bevy_ecs::world::World
 -- exit_on_all_closed and process_output_system (in set ProcessOutput)
    conflict on: ["bevy_window::window::Window"]
 -- apply_deferred (in set SyncBackend) and process_output_system (in set ProcessOutput)
    conflict on: bevy_ecs::world::World
 -- apply_deferred (in set SyncBackend) and update_egui_textures_system
    conflict on: bevy_ecs::world::World
 -- writeback_rigid_bodies (in set Writeback) and writeback_mass_properties (in set Writeback)
    conflict on: ["bevy_rapier2d::plugin::context::RapierContext"]

@ThierryBerger
Copy link
Copy Markdown
Contributor Author

closed in favor of dimforge/rapier#659

@ThierryBerger ThierryBerger changed the title add simpler reproduction + a 'fix' in userspace joints example bug reproduction + a 'fix' in userspace Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant