diff options
author | Zae <zaevi@live.com> | 2021-10-22 19:44:38 +0800 |
---|---|---|
committer | Zae <zaevi@live.com> | 2021-10-23 13:01:52 +0800 |
commit | 924c2078dae69e73032af04e96200f44187d2c8d (patch) | |
tree | dcc13350670b4c231e45a6b120f9f1d1e42d9c5d | |
parent | fe3d62f2dc9a9bb37b6f9a1e17a7f16fa153aca8 (diff) |
Fix unexpected crashes in `notification`
-rw-r--r-- | scene/2d/collision_polygon_2d.cpp | 1 | ||||
-rw-r--r-- | scene/2d/collision_shape_2d.cpp | 2 | ||||
-rw-r--r-- | scene/2d/ray_cast_2d.cpp | 1 | ||||
-rw-r--r-- | scene/gui/control.cpp | 12 |
4 files changed, 13 insertions, 3 deletions
diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index 271a4da705..00bfa62449 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -131,6 +131,7 @@ void CollisionPolygon2D::_notification(int p_what) { } break; case NOTIFICATION_DRAW: { + ERR_FAIL_COND(!is_inside_tree()); if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) { break; } diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index 54cb851216..c7742c7ba5 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -88,6 +88,8 @@ void CollisionShape2D::_notification(int p_what) { } break; case NOTIFICATION_DRAW: { + ERR_FAIL_COND(!is_inside_tree()); + if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) { break; } diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index 3ac2128c2e..0a8e9e2a58 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -157,6 +157,7 @@ void RayCast2D::_notification(int p_what) { } break; case NOTIFICATION_DRAW: { + ERR_FAIL_COND(!is_inside_tree()); if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) { break; } diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 973074397b..e4048fbf09 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -637,7 +637,9 @@ void Control::_notification(int p_notification) { } } else { //is a regular root control or top_level - data.RI = get_viewport()->_gui_add_root_control(this); + Viewport *viewport = get_viewport(); + ERR_FAIL_COND(!viewport); + data.RI = viewport->_gui_add_root_control(this); } data.parent_canvas_item = get_parent_item(); @@ -646,7 +648,9 @@ void Control::_notification(int p_notification) { data.parent_canvas_item->connect("item_rect_changed", callable_mp(this, &Control::_size_changed)); } else { //connect viewport - get_viewport()->connect("size_changed", callable_mp(this, &Control::_size_changed)); + Viewport *viewport = get_viewport(); + ERR_FAIL_COND(!viewport); + viewport->connect("size_changed", callable_mp(this, &Control::_size_changed)); } } break; case NOTIFICATION_EXIT_CANVAS: { @@ -655,7 +659,9 @@ void Control::_notification(int p_notification) { data.parent_canvas_item = nullptr; } else if (!is_set_as_top_level()) { //disconnect viewport - get_viewport()->disconnect("size_changed", callable_mp(this, &Control::_size_changed)); + Viewport *viewport = get_viewport(); + ERR_FAIL_COND(!viewport); + viewport->disconnect("size_changed", callable_mp(this, &Control::_size_changed)); } if (data.RI) { |