Repository: godotengine/godot
File: scene/main/viewport.cpp (C++)

Code before:
			}
#endif // PHYSICS_2D_DISABLED

#ifndef PHYSICS_3D_DISABLED
			if (contact_3d_debug_multimesh.is_valid()) {
				RenderingServer::get_singleton()->free_rid(contact_3d_debug_multimesh);
				RenderingServer::get_singleton()->free_rid(contact_3d_debug_instance);
				contact_3d_debug_instance = RID();
				contact_3d_debug_multimesh = RID();
			}
#endif // PHYSICS_3D_DISABLED

			remove_from_group("_viewports");
			set_physics_process_internal(false);

			RS::get_singleton()->viewport_set_active(viewport, false);
			RenderingServer::get_singleton()->viewport_set_parent_viewport(viewport, RID());
		} break;

		case NOTIFICATION_PATH_RENAMED: {
			_update_viewport_path();
		} break;

#ifndef XR_DISABLED
		case NOTIFICATION_INTERNAL_PROCESS: {
			// Note: internal process should only be enabled if use_xr it true,
			// but we check anyway to be future proof.
			// This is currently a polling approach.
			if (use_xr) {
				_check_xr_size();
			}
		} break;
#endif // XR_DISABLED

#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
		case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
			if (!get_tree()) {
				return;
			}

#ifndef PHYSICS_2D_DISABLED
			if (get_tree()->is_debugging_collisions_hint() && contact_2d_debug.is_valid()) {
				RenderingServer::get_singleton()->canvas_item_clear(contact_2d_debug);
				RenderingServer::get_singleton()->canvas_item_set_draw_index(contact_2d_debug, 0xFFFFF); //very high index

				Vector<Vector2> points = PhysicsServer2D::get_singleton()->space_get_contacts(find_world_2d()->get_space());
				int point_count = PhysicsServer2D::get_singleton()->space_get_contact_count(find_world_2d()->get_space());
				Color ccol = get_tree()->get_debug_collision_contact_color();

				for (int i = 0; i < point_count; i++) {
					RenderingServer::get_singleton()->canvas_item_add_rect(contact_2d_debug, Rect2(points[i] - Vector2(2, 2), Vector2(5, 5)), ccol);

Review comment (suggestion):
```suggestion
			// Note: internal process should only be enabled if use_xr is true,
```

Code after:
			RenderingServer::get_singleton()->viewport_remove_canvas(viewport, current_canvas);
#ifndef PHYSICS_2D_DISABLED
			if (contact_2d_debug.is_valid()) {
				RenderingServer::get_singleton()->free_rid(contact_2d_debug);
				contact_2d_debug = RID();
			}
#endif // PHYSICS_2D_DISABLED

#ifndef PHYSICS_3D_DISABLED
			if (contact_3d_debug_multimesh.is_valid()) {
				RenderingServer::get_singleton()->free_rid(contact_3d_debug_multimesh);
				RenderingServer::get_singleton()->free_rid(contact_3d_debug_instance);
				contact_3d_debug_instance = RID();
				contact_3d_debug_multimesh = RID();
			}
#endif // PHYSICS_3D_DISABLED

			remove_from_group("_viewports");
			set_physics_process_internal(false);

			RS::get_singleton()->viewport_set_active(viewport, false);
			RenderingServer::get_singleton()->viewport_set_parent_viewport(viewport, RID());
		} break;

		case NOTIFICATION_PATH_RENAMED: {
			_update_viewport_path();
		} break;

#ifndef XR_DISABLED
		case NOTIFICATION_INTERNAL_PROCESS: {
			// Note: internal process should only be enabled if use_xr is true,
			// but we check anyway to be future proof.
			// This is currently a polling approach.
			if (use_xr) {
				_check_xr_size();
			}
		} break;
#endif // XR_DISABLED

#if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
		case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
			if (!get_tree()) {
				return;
			}

#ifndef PHYSICS_2D_DISABLED
			if (get_tree()->is_debugging_collisions_hint() && contact_2d_debug.is_valid()) {
				RenderingServer::get_singleton()->canvas_item_clear(contact_2d_debug);
				RenderingServer::get_singleton()->canvas_item_set_draw_index(contact_2d_debug, 0xFFFFF); //very high index

				Vector<Vector2> points = PhysicsServer2D::get_singleton()->space_get_contacts(find_world_2d()->get_space());