From 20bad6e29aa01ba3a62d43958a02333a96716432 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 8 Jul 2025 15:42:59 +0200 Subject: [PATCH] Fix #141477: Crash during material selection Material selection didn't support empty geometries. Geometry list can have nullptrs, when meshes contain more than 16 materials, but some materials slots are not actually used in the mesh. Material selection used to still looped over all the materials and tried to draw geometry that aren't there. Regression from !139781 Pull Request: https://projects.blender.org/blender/blender/pulls/141608 --- source/blender/draw/engines/overlay/overlay_prepass.hh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/blender/draw/engines/overlay/overlay_prepass.hh b/source/blender/draw/engines/overlay/overlay_prepass.hh index dd205883f97..63669b40b0d 100644 --- a/source/blender/draw/engines/overlay/overlay_prepass.hh +++ b/source/blender/draw/engines/overlay/overlay_prepass.hh @@ -280,10 +280,16 @@ class Prepass : Overlay { ResourceHandle res_handle = manager.unique_handle(ob_ref); for (int material_id : geom_list.index_range()) { + /* Meshes with more than 16 materials can have nullptr in the geometry list as materials are + * not filled for unused materials indices. We should actually use `material_indices_used` + * but these are only available for meshes. */ + if (geom_list[material_id] == nullptr) { + continue; + } + select::ID select_id = use_material_slot_selection_ ? res.select_id(ob_ref, (material_id + 1) << 16) : res.select_id(ob_ref); - if (res.is_selection() && (pass == mesh_ps_)) { /* Conservative shader needs expanded draw-call. */ pass->draw_expand(