Skip to content
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

Hide NavigationRegion2D's debug instance instead of freeing it, and hide it when navigation_polygon is set to null. #100006

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions scene/2d/navigation_region_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,14 @@ void NavigationRegion2D::_notification(int p_what) {

case NOTIFICATION_VISIBILITY_CHANGED: {
#ifdef DEBUG_ENABLED
if (debug_instance_rid.is_valid()) {
RS::get_singleton()->canvas_item_set_visible(debug_instance_rid, is_visible_in_tree());
}
_set_debug_visibile(is_visible_in_tree());
#endif // DEBUG_ENABLED
} break;

case NOTIFICATION_EXIT_TREE: {
_region_exit_navigation_map();
#ifdef DEBUG_ENABLED
_free_debug();
_set_debug_visibile(false);
#endif // DEBUG_ENABLED
} break;

Expand Down Expand Up @@ -208,6 +206,13 @@ void NavigationRegion2D::set_navigation_polygon(const Ref<NavigationPolygon> &p_
if (navigation_polygon.is_valid()) {
navigation_polygon->connect_changed(callable_mp(this, &NavigationRegion2D::_navigation_polygon_changed));
}

#ifdef DEBUG_ENABLED
if (navigation_polygon.is_null()) {
_set_debug_visibile(false);
}
#endif // DEBUG_ENABLED

_navigation_polygon_changed();

update_configuration_warnings();
Expand Down Expand Up @@ -392,6 +397,12 @@ NavigationRegion2D::~NavigationRegion2D() {
#ifdef DEBUG_ENABLED
NavigationServer2D::get_singleton()->disconnect(SNAME("map_changed"), callable_mp(this, &NavigationRegion2D::_navigation_map_changed));
NavigationServer2D::get_singleton()->disconnect(SNAME("navigation_debug_changed"), callable_mp(this, &NavigationRegion2D::_navigation_debug_changed));
if (debug_instance_rid.is_valid()) {
RS::get_singleton()->free(debug_instance_rid);
}
if (debug_mesh_rid.is_valid()) {
RS::get_singleton()->free(debug_mesh_rid);
}
#endif // DEBUG_ENABLED
}

Expand Down Expand Up @@ -435,7 +446,7 @@ void NavigationRegion2D::_region_update_transform() {
#ifdef DEBUG_ENABLED
void NavigationRegion2D::_update_debug_mesh() {
if (!is_inside_tree()) {
_free_debug();
_set_debug_visibile(false);
return;
}

Expand Down Expand Up @@ -630,17 +641,11 @@ void NavigationRegion2D::_update_debug_baking_rect() {
#endif // DEBUG_ENABLED

#ifdef DEBUG_ENABLED
void NavigationRegion2D::_free_debug() {
void NavigationRegion2D::_set_debug_visibile(bool p_visible) {
RenderingServer *rs = RenderingServer::get_singleton();
ERR_FAIL_NULL(rs);
if (debug_instance_rid.is_valid()) {
rs->canvas_item_clear(debug_instance_rid);
rs->free(debug_instance_rid);
debug_instance_rid = RID();
}
if (debug_mesh_rid.is_valid()) {
rs->free(debug_mesh_rid);
debug_mesh_rid = RID();
RS::get_singleton()->canvas_item_set_visible(debug_instance_rid, p_visible);
}
}
#endif // DEBUG_ENABLED
2 changes: 1 addition & 1 deletion scene/2d/navigation_region_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class NavigationRegion2D : public Node2D {

bool debug_mesh_dirty = true;

void _free_debug();
void _set_debug_visibile(bool p_visible);
void _update_debug_mesh();
void _update_debug_edge_connections_mesh();
void _update_debug_baking_rect();
Expand Down
Loading