mirror of
https://github.com/godotengine/godot.git
synced 2024-11-27 09:16:35 +08:00
Fixed, chance of crash when Control overrides mouse input on Area2D
Made Viewport::_cleanup_mouseover_colliders queue up mouse_exit and mouse_shape_exit signals to emit and at the end of the function's execution to avoid potential crashes.
This commit is contained in:
parent
c495eb5102
commit
dbb01bc451
@ -2513,6 +2513,7 @@ void Viewport::_drop_physics_mouseover(bool p_paused_only) {
|
||||
|
||||
void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paused_only, uint64_t p_frame_reference) {
|
||||
List<ObjectID> to_erase;
|
||||
List<ObjectID> to_mouse_exit;
|
||||
|
||||
for (const KeyValue<ObjectID, uint64_t> &E : physics_2d_mouseover) {
|
||||
if (!p_clean_all_frames && E.value == p_frame_reference) {
|
||||
@ -2526,7 +2527,7 @@ void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paus
|
||||
if (p_clean_all_frames && p_paused_only && co->can_process()) {
|
||||
continue;
|
||||
}
|
||||
co->_mouse_exit();
|
||||
to_mouse_exit.push_back(E.key);
|
||||
}
|
||||
}
|
||||
to_erase.push_back(E.key);
|
||||
@ -2539,6 +2540,7 @@ void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paus
|
||||
|
||||
// Per-shape.
|
||||
List<Pair<ObjectID, int>> shapes_to_erase;
|
||||
List<Pair<ObjectID, int>> shapes_to_mouse_exit;
|
||||
|
||||
for (KeyValue<Pair<ObjectID, int>, uint64_t> &E : physics_2d_shape_mouseover) {
|
||||
if (!p_clean_all_frames && E.value == p_frame_reference) {
|
||||
@ -2552,7 +2554,7 @@ void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paus
|
||||
if (p_clean_all_frames && p_paused_only && co->can_process()) {
|
||||
continue;
|
||||
}
|
||||
co->_mouse_shape_exit(E.key.second);
|
||||
shapes_to_mouse_exit.push_back(E.key);
|
||||
}
|
||||
}
|
||||
shapes_to_erase.push_back(E.key);
|
||||
@ -2562,6 +2564,21 @@ void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paus
|
||||
physics_2d_shape_mouseover.erase(shapes_to_erase.front()->get());
|
||||
shapes_to_erase.pop_front();
|
||||
}
|
||||
|
||||
while (to_mouse_exit.size()) {
|
||||
Object *o = ObjectDB::get_instance(to_mouse_exit.front()->get());
|
||||
CollisionObject2D *co = Object::cast_to<CollisionObject2D>(o);
|
||||
co->_mouse_exit();
|
||||
to_mouse_exit.pop_front();
|
||||
}
|
||||
|
||||
while (shapes_to_mouse_exit.size()) {
|
||||
Pair<ObjectID, int> e = shapes_to_mouse_exit.front()->get();
|
||||
Object *o = ObjectDB::get_instance(e.first);
|
||||
CollisionObject2D *co = Object::cast_to<CollisionObject2D>(o);
|
||||
co->_mouse_shape_exit(e.second);
|
||||
shapes_to_mouse_exit.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
void Viewport::_gui_grab_click_focus(Control *p_control) {
|
||||
|
Loading…
Reference in New Issue
Block a user