Repository: godotengine/godot
File: modules/gridmap/grid_map.cpp (C++)

Code before:
	ERR_FAIL_COND(!octant_map.has(p_key));
	Octant &g = *octant_map[p_key];

	if (!NavigationServer3D::get_singleton()->get_debug_navigation_enabled()) {
		if (g.navigation_debug_edge_connections_instance.is_valid()) {
			RS::get_singleton()->instance_set_visible(g.navigation_debug_edge_connections_instance, false);
		}
		return;
	}

	if (!is_inside_tree()) {
		return;
	}

	if (!bake_navigation) {
		if (g.navigation_debug_edge_connections_instance.is_valid()) {
			RS::get_singleton()->instance_set_visible(g.navigation_debug_edge_connections_instance, false);
		}
		return;
	}

	if (!g.navigation_debug_edge_connections_instance.is_valid()) {
		g.navigation_debug_edge_connections_instance = RenderingServer::get_singleton()->instance_create();
	}

	if (!g.navigation_debug_edge_connections_mesh.is_valid()) {
		g.navigation_debug_edge_connections_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
	}

	g.navigation_debug_edge_connections_mesh->clear_surfaces();

	float edge_connection_margin = NavigationServer3D::get_singleton()->map_get_edge_connection_margin(get_world_3d()->get_navigation_map());
	float half_edge_connection_margin = edge_connection_margin * 0.5;

	Vector<Vector3> vertex_array;

	for (KeyValue<IndexKey, Octant::NavigationCell> &F : g.navigation_cell_ids) {
		if (cell_map.has(F.key) && F.value.region.is_valid()) {
			int connections_count = NavigationServer3D::get_singleton()->region_get_connections_count(F.value.region);
			if (connections_count == 0) {
				continue;
			}

			for (int i = 0; i < connections_count; i++) {
				Vector3 connection_pathway_start = NavigationServer3D::get_singleton()->region_get_connection_pathway_start(F.value.region, i);
				Vector3 connection_pathway_end = NavigationServer3D::get_singleton()->region_get_connection_pathway_end(F.value.region, i);

				Vector3 direction_start_end = connection_pathway_start.direction_to(connection_pathway_end);
				Vector3 direction_end_start = connection_pathway_end.direction_to(connection_pathway_start);

				Vector3 start_right_dir = direction_start_end.cross(Vector3(0, 1, 0));

Review comment (bug):
```suggestion
	if (g.navigation_debug_edge_connections_mesh.is_null()) {
```

Code after:
	ERR_FAIL_COND(!octant_map.has(p_key));
	Octant &g = *octant_map[p_key];

	if (!NavigationServer3D::get_singleton()->get_debug_navigation_enabled()) {
		if (g.navigation_debug_edge_connections_instance.is_valid()) {
			RS::get_singleton()->instance_set_visible(g.navigation_debug_edge_connections_instance, false);
		}
		return;
	}

	if (!is_inside_tree()) {
		return;
	}

	if (!bake_navigation) {
		if (g.navigation_debug_edge_connections_instance.is_valid()) {
			RS::get_singleton()->instance_set_visible(g.navigation_debug_edge_connections_instance, false);
		}
		return;
	}

	if (!g.navigation_debug_edge_connections_instance.is_valid()) {
		g.navigation_debug_edge_connections_instance = RenderingServer::get_singleton()->instance_create();
	}

	if (g.navigation_debug_edge_connections_mesh.is_null()) {
		g.navigation_debug_edge_connections_mesh.instantiate();
	}

	g.navigation_debug_edge_connections_mesh->clear_surfaces();

	float edge_connection_margin = NavigationServer3D::get_singleton()->map_get_edge_connection_margin(get_world_3d()->get_navigation_map());
	float half_edge_connection_margin = edge_connection_margin * 0.5;

	Vector<Vector3> vertex_array;

	for (KeyValue<IndexKey, Octant::NavigationCell> &F : g.navigation_cell_ids) {
		if (cell_map.has(F.key) && F.value.region.is_valid()) {
			int connections_count = NavigationServer3D::get_singleton()->region_get_connections_count(F.value.region);
			if (connections_count == 0) {
				continue;
			}

			for (int i = 0; i < connections_count; i++) {
				Vector3 connection_pathway_start = NavigationServer3D::get_singleton()->region_get_connection_pathway_start(F.value.region, i);
				Vector3 connection_pathway_end = NavigationServer3D::get_singleton()->region_get_connection_pathway_end(F.value.region, i);

				Vector3 direction_start_end = connection_pathway_start.direction_to(connection_pathway_end);
				Vector3 direction_end_start = connection_pathway_end.direction_to(connection_pathway_start);

				Vector3 start_right_dir = direction_start_end.cross(Vector3(0, 1, 0));