-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Fix dragging-over panic #21999
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
Fix dragging-over panic #21999
Conversation
…`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.
…` in the frame the drag begins.
| .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(); |
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.
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?
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.
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>
|
I checked out the branch and confirmed that the examples listed in the |
Objective
Problems:
If a drag starts over a hovered entity,
picking_eventsdoesn't add the hovered entity to thedragging_overmap inPointerButtonState. This causes a panic when the pointer is moved andpicking_eventstries to update the non-existantdragging_overstate for the hovered entity.DragEnterisn't dispatched onDragStart. 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
dragging_statefor all hovered entities every frame, before handling anyPointerInputs.DragEnterdispatch logic.DragEnternow also fires when a drag starts over an already hovered entity.Testing
The examples using drag events should no longer panic: