[Bf-blender-cvs] [e41437b16e6] master: Fix T81268: Crash when undo from Sculpt Mode to Edit Mode

Pablo Dobarro noreply at git.blender.org
Thu Oct 1 19:18:41 CEST 2020


Commit: e41437b16e6deda9fdc23ffd4baeaf912dc7052f
Author: Pablo Dobarro
Date:   Thu Oct 1 19:18:12 2020 +0200
Branches: master
https://developer.blender.org/rBe41437b16e6deda9fdc23ffd4baeaf912dc7052f

Fix T81268: Crash when undo from Sculpt Mode to Edit Mode

This was introduced in 6c9ec1c893f9. The overlays can now be drawn when
PBVH drawing is not enabled, but the PBVH should still exist in the
SculptSession in order to draw them. Before, it was avoiding the crash
by checking use_pbvh as BKE_sculptsession_use_pbvh_draw also checks if
the PBVH exists.

Reviewed By: sergey

Maniphest Tasks: T81268

Differential Revision: https://developer.blender.org/D9044

===================================================================

M	source/blender/draw/engines/overlay/overlay_sculpt.c

===================================================================

diff --git a/source/blender/draw/engines/overlay/overlay_sculpt.c b/source/blender/draw/engines/overlay/overlay_sculpt.c
index c6c617fd29b..a3860c9e25e 100644
--- a/source/blender/draw/engines/overlay/overlay_sculpt.c
+++ b/source/blender/draw/engines/overlay/overlay_sculpt.c
@@ -54,15 +54,26 @@ void OVERLAY_sculpt_cache_populate(OVERLAY_Data *vedata, Object *ob)
 
   const bool use_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d);
 
-  if (pbvh_has_mask(pbvh) || pbvh_has_face_sets(pbvh)) {
-    if (use_pbvh) {
-      DRW_shgroup_call_sculpt(pd->sculpt_mask_grp, ob, false, true);
-    }
-    else {
-      sculpt_overlays = DRW_mesh_batch_cache_get_sculpt_overlays(ob->data);
-      if (sculpt_overlays) {
-        DRW_shgroup_call(pd->sculpt_mask_grp, sculpt_overlays, ob);
-      }
+  if (!pbvh) {
+    /* It is possible to have SculptSession without PBVH. This happens, for example, when toggling
+     * object mode to sculpt then to edit mode. */
+    return;
+  }
+
+  if (!pbvh_has_mask(pbvh) && !pbvh_has_face_sets(pbvh)) {
+    /* The SculptSession and the PBVH can be created without a Mask datalayer or Face Set
+     * datalayer. (masks datalayers are created after using a mask tool), so in these cases there
+     * is nothing to draw. */
+    return;
+  }
+
+  if (use_pbvh) {
+    DRW_shgroup_call_sculpt(pd->sculpt_mask_grp, ob, false, true);
+  }
+  else {
+    sculpt_overlays = DRW_mesh_batch_cache_get_sculpt_overlays(ob->data);
+    if (sculpt_overlays) {
+      DRW_shgroup_call(pd->sculpt_mask_grp, sculpt_overlays, ob);
     }
   }
 }



More information about the Bf-blender-cvs mailing list