Merging r58701 through r58746 from trunk into soc-2013-depsgraph_mt
[blender.git] / source / blender / editors / sculpt_paint / sculpt.c
index 6181861a6e30fb9b646da99cc2964948d9449b4b..9720256df056954ea723179f51d18de4865c0569 100644 (file)
@@ -4591,14 +4591,21 @@ void sculpt_dynamic_topology_enable(bContext *C)
        Object *ob = CTX_data_active_object(C);
        SculptSession *ss = ob->sculpt;
        Mesh *me = ob->data;
+       const BMAllocTemplate allocsize = {me->totvert,
+                                          me->totedge,
+                                          me->totloop,
+                                          me->totpoly};
 
        sculpt_pbvh_clear(ob);
 
        ss->bm_smooth_shading = (scene->toolsettings->sculpt->flags &
                                 SCULPT_DYNTOPO_SMOOTH_SHADING);
 
+       /* Dynamic topology doesn't ensure selection state is valid, so remove [#36280] */
+       BKE_mesh_mselect_clear(me);
+
        /* Create triangles-only BMesh */
-       ss->bm = BM_mesh_create(&bm_mesh_allocsize_default);
+       ss->bm = BM_mesh_create(&allocsize);
 
        BM_mesh_bm_from_me(ss->bm, me, true, true, ob->shapenr);
        sculpt_dynamic_topology_triangulate(ss->bm);