Repository: godotengine/godot (language: cpp)

Issue:
[4.4 dev7] Seperation Ray causes Mesh surface errors
### Tested versions

-reproducible in 4.4 Dev 7, mono version 

### System information

Godot v4.4.dev7.mono - Windows 10 (build 19045) - Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1070 (NVIDIA; 32.0.15.6094) - Intel(R) Core(TM) i5-7640X CPU @ 4.00GHz (4 threads)

### Issue description

Three errors are thrown when starting a scene with a CollisionShape3D with shape set to Seperation Ray.
![Image](https://github.com/user-attachments/assets/8da0920f-c8db-420f-9ff6-c955df909800)


### Steps to reproduce

Open the attached project. Run the main scene.

Alternatively, run a scene with a CollisionShape3D, with the shape set to Seperation Ray.

### Minimal reproduction project (MRP)

[surface-error-example.zip](https://github.com/user-attachments/files/18215122/surface-error-example.zip)



Discussion / hints:
Seems a regression between 4.4 dev 5 and 4.4 dev 6, also, the bug needs `Debug -> Visible Collision Shapes` enabled to happen. I'll start the bisect.
Bisescted to #90644, @BattyBovine

![Image](https://github.com/user-attachments/assets/47b5b20f-de9f-4c5c-a147-8bb9ff238e95)

I managed to reproduce this issue. It seems like it should be an easy fix. The only issue here seems to be that the separation ray generates an empty debug mesh array, which Godot does not like. I'll get a fix for it soon.

Fix patch:
diff --git a/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp b/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp
index 6db68f413ebd..db9a9bef04b2 100644
--- a/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp
+++ b/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp
@@ -350,7 +350,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
 
 	if (cs->get_debug_fill_enabled()) {
 		Ref<ArrayMesh> array_mesh = s->get_debug_arraymesh_faces(collision_color);
-		if (array_mesh.is_valid()) {
+		if (array_mesh.is_valid() && array_mesh->get_surface_count() > 0) {
 			p_gizmo->add_mesh(array_mesh, material_arraymesh);
 		}
 	}
diff --git a/scene/resources/3d/shape_3d.cpp b/scene/resources/3d/shape_3d.cpp
index 63d424fb3724..4eae3ffeb2e5 100644
--- a/scene/resources/3d/shape_3d.cpp
+++ b/scene/resources/3d/shape_3d.cpp
@@ -132,9 +132,12 @@ Ref<ArrayMesh> Shape3D::get_debug_mesh() {
 		debug_mesh_cache->surface_set_material(0, material);
 
 		if (debug_fill) {
-			Array solid_array = get_debug_arraymesh_faces(debug_color * Color(1.0, 1.0, 1.0, 0.0625))->surface_get_arrays(0);
-			debug_mesh_cache->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, solid_array);
-			debug_mesh_cache->surface_set_material(1, material);
+			Ref<ArrayMesh> array_mesh = get_debug_arraymesh_faces(debug_color * Color(1.0, 1.0, 1.0, 0.0625));
+			if (array_mesh.is_valid() && array_mesh->get_surface_count() > 0) {
+				Array solid_array = array_mesh->surface_get_arrays(0);
+				debug_mesh_cache->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, solid_array);
+				debug_mesh_cache->surface_set_material(1, material);
+			}
 		}
 	}
 


Test patch: