Skip to content

Conversation

@ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Dec 1, 2025

Objective

Problems:

  • If a drag starts over a hovered entity, picking_events doesn't add the hovered entity to the dragging_over map in PointerButtonState. This causes a panic when the pointer is moved and picking_events tries to update the non-existant dragging_over state for the hovered entity.

  • DragEnter isn't dispatched on DragStart. This doesn't seem ideal. The drag isn't crossing a geometric boundary, but it is causing the dragged over entities to enter into a dragged over state.

Fixes #21998

Solution

  • Update the dragging_state for all hovered entities every frame, before handling any PointerInputs.
  • Reworked the DragEnter dispatch logic. DragEnter now also fires when a drag starts over an already hovered entity.

Testing

The examples using drag events should no longer panic:

cargo run --example standard_widgets --features="experimental_bevy_ui_widgets"
cargo run --example ui_drag_and_drop

…`dragged_over` map in `PointerButtonState` if the drag started with the dragged over entity already hovered. This causes a panic when the pointer is moved and it tries to look up the `dragging_over` state for the hovered entity.

This PR changes `picking_events` to update the `dragging_state` for all hovered entities every frame, before handling the `PointerInput`s.

It also changes the behaviour of the `DragEnter` event. `DragEnter` now also fires when a drag starts over an already hovered entity.
@ickshonpe ickshonpe added A-Picking Pointing at and selecting objects of all sorts P-Crash A sudden unexpected crash C-Bug An unexpected or incorrect behavior P-Regression Functionality that used to work but no longer does. Add a test for this! M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 1, 2025
@ickshonpe ickshonpe changed the title Fix dragging over panic Fix dragging-over panic Dec 1, 2025
@ickshonpe ickshonpe added the C-Code-Quality A section of code that is hard to understand or change label Dec 1, 2025
@alice-i-cecile alice-i-cecile added this to the 0.18 milestone Dec 1, 2025
.flat_map(|h| h.iter().map(|(entity, data)| (*entity, data.to_owned())))
.filter(|(hovered_entity, _)| *hovered_entity != *drag_target)
{
*state.dragging_over.get_mut(&hovered_entity).unwrap() = hit.clone();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this was the line that caused the panic. Is it valid to delete this line? Is it because it’s redundant now with the logic you put in?

Copy link
Contributor Author

@ickshonpe ickshonpe Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this line was a fix for another bug: #21849. It's redundant with this PR as the dragging_over states are already updated before the PointerInputs are processed.

Co-authored-by: Kevin Chen <chen.kevin.f@gmail.com>
@kfc35
Copy link
Contributor

kfc35 commented Dec 1, 2025

I checked out the branch and confirmed that the examples listed in the testing section no longer panic with drag-and-drops

@ickshonpe ickshonpe added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 2, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Dec 3, 2025
Merged via the queue into bevyengine:main with commit 8978b47 Dec 3, 2025
36 checks passed
@ickshonpe ickshonpe mentioned this pull request Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Picking Pointing at and selecting objects of all sorts C-Bug An unexpected or incorrect behavior C-Code-Quality A section of code that is hard to understand or change M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide P-Crash A sudden unexpected crash P-Regression Functionality that used to work but no longer does. Add a test for this! S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic when a drag starts over an already hovered entity

4 participants