Skip to content

Commit 6dc6ad2

Browse files
committed
Prevent errors when drawing debug meshes when surface count is zero.
Adds a few checks to ensure a debug collision mesh contains mesh data before attempting to add it to the gizmo draw list. This prevents errors when using SeparationRayShape3D, which is only intended to draw a single line, and contains no mesh data. Closes godotengine#100665
1 parent 4cf0231 commit 6dc6ad2

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
350350

351351
if (cs->get_debug_fill_enabled()) {
352352
Ref<ArrayMesh> array_mesh = s->get_debug_arraymesh_faces(collision_color);
353-
if (array_mesh.is_valid()) {
353+
if (array_mesh.is_valid() && array_mesh->get_surface_count() > 0) {
354354
p_gizmo->add_mesh(array_mesh, material_arraymesh);
355355
}
356356
}

scene/resources/3d/shape_3d.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,12 @@ Ref<ArrayMesh> Shape3D::get_debug_mesh() {
132132
debug_mesh_cache->surface_set_material(0, material);
133133

134134
if (debug_fill) {
135-
Array solid_array = get_debug_arraymesh_faces(debug_color * Color(1.0, 1.0, 1.0, 0.0625))->surface_get_arrays(0);
136-
debug_mesh_cache->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, solid_array);
137-
debug_mesh_cache->surface_set_material(1, material);
135+
Ref<ArrayMesh> array_mesh = get_debug_arraymesh_faces(debug_color * Color(1.0, 1.0, 1.0, 0.0625));
136+
if (array_mesh.is_valid() && array_mesh->get_surface_count() > 0) {
137+
Array solid_array = array_mesh->surface_get_arrays(0);
138+
debug_mesh_cache->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, solid_array);
139+
debug_mesh_cache->surface_set_material(1, material);
140+
}
138141
}
139142
}
140143

0 commit comments

Comments
 (0)