Fix crash when accessing mesh from python while a mesh with a subsurf modifier
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 19 May 2011 11:24:56 +0000 (11:24 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 19 May 2011 11:24:56 +0000 (11:24 +0000)
is in editmode.

source/blender/blenkernel/BKE_subsurf.h
source/blender/blenkernel/intern/multires.c
source/blender/blenkernel/intern/shrinkwrap.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/modifiers/intern/MOD_subsurf.c

index b82db853d371d13709acfd53d14c9c61120b310f..a400c1e27b95e56b79379d76753b62a5537629b1 100644 (file)
@@ -54,7 +54,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
                                                struct DerivedMesh *dm,
                                                struct SubsurfModifierData *smd,
                                                int useRenderParams, float (*vertCos)[3],
-                                               int isFinalCalc, int editMode);
+                                               int isFinalCalc, int forEditMode, int inEditMode);
 
 void subsurf_calculate_limit_positions(struct Mesh *me, float (*positions_r)[3]);
 
index 5706a3997e67f5cc0af40a2ca7770a558b248a53..637f5da45afdbbd9f0f54aa1535ad8eae7c91da2 100644 (file)
@@ -465,7 +465,7 @@ static DerivedMesh *multires_dm_create_local(Object *ob, DerivedMesh *dm, int lv
        return multires_dm_create_from_derived(&mmd, 1, dm, ob, 0, 0);
 }
 
-static DerivedMesh *subsurf_dm_create_local(Object *UNUSED(ob), DerivedMesh *dm, int lvl, int simple, int optimal)
+static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm, int lvl, int simple, int optimal)
 {
        SubsurfModifierData smd= {{NULL}};
 
@@ -476,7 +476,7 @@ static DerivedMesh *subsurf_dm_create_local(Object *UNUSED(ob), DerivedMesh *dm,
        if(optimal)
                smd.flags |= eSubsurfModifierFlag_ControlEdges;
 
-       return subsurf_make_derived_from_derived(dm, &smd, 0, NULL, 0, 0);
+       return subsurf_make_derived_from_derived(dm, &smd, 0, NULL, 0, 0, (ob->mode & OB_MODE_EDIT));
 }
 
 
index 5b6c6bf87328720d0785f627773a633d02f775c9..7b04a72666d8252f2fcfc422e2a502c0cb8c4a67 100644 (file)
@@ -562,7 +562,7 @@ void shrinkwrapModifier_deform(ShrinkwrapModifierData *smd, Object *ob, DerivedM
                        ssmd.subdivType = ME_CC_SUBSURF;                //catmull clark
                        ssmd.levels             = smd->subsurfLevels;   //levels
 
-                       ss_mesh = subsurf_make_derived_from_derived(dm, &ssmd, FALSE, NULL, 0, 0);
+                       ss_mesh = subsurf_make_derived_from_derived(dm, &ssmd, FALSE, NULL, 0, 0, (ob->mode & OB_MODE_EDIT));
 
                        if(ss_mesh)
                        {
index 5d44841df8b698b32e077717318bff0f786fdf08..a66caf8879f2b79679d9d9032e51ac108a864b4b 100644 (file)
@@ -2617,7 +2617,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
                                                struct DerivedMesh *dm,
                                                struct SubsurfModifierData *smd,
                                                int useRenderParams, float (*vertCos)[3],
-                                               int isFinalCalc, int editMode)
+                                               int isFinalCalc, int forEditMode, int inEditMode)
 {
        int useSimple = smd->subdivType == ME_SIMPLE_SUBSURF;
        int useAging = smd->flags & eSubsurfModifierFlag_DebugIncr;
@@ -2625,7 +2625,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
        int drawInteriorEdges = !(smd->flags & eSubsurfModifierFlag_ControlEdges);
        CCGDerivedMesh *result;
 
-       if(editMode) {
+       if(forEditMode) {
                int levels= (smd->modifier.scene)? get_render_subsurf_level(&smd->modifier.scene->r, smd->levels): smd->levels;
 
                smd->emCache = _getSubSurf(smd->emCache, levels, useAging, 0,
@@ -2656,7 +2656,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
                int useAging = smd->flags & eSubsurfModifierFlag_DebugIncr;
                int levels= (smd->modifier.scene)? get_render_subsurf_level(&smd->modifier.scene->r, smd->levels): smd->levels;
                CCGSubSurf *ss;
-               
+
                /* It is quite possible there is a much better place to do this. It
                 * depends a bit on how rigourously we expect this function to never
                 * be called in editmode. In semi-theory we could share a single
@@ -2664,8 +2664,11 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
                 * the same so we would need some way of converting them. Its probably
                 * not worth the effort. But then why am I even writing this long
                 * comment that no one will read? Hmmm. - zr
+                *
+                * Addendum: we can't really ensure that this is never called in edit
+                * mode, so now we have a parameter to verify it. - brecht
                 */
-               if(smd->emCache) {
+               if(!inEditMode && smd->emCache) {
                        ccgSubSurf_free(smd->emCache);
                        smd->emCache = NULL;
                }
index fc9958b08d045ba57cc5a670b76bbbf547fb9aa3..e3e09f660aaa26bf14b9ac5e964a7ca4262d20cc 100644 (file)
@@ -91,7 +91,7 @@ static int isDisabled(ModifierData *md, int useRenderParams)
        return get_render_subsurf_level(&md->scene->r, levels) == 0;
 }
 
-static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
+static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
                                                DerivedMesh *derivedData,
                                                int useRenderParams,
                                                int isFinalCalc)
@@ -100,7 +100,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
        DerivedMesh *result;
 
        result = subsurf_make_derived_from_derived(derivedData, smd,
-                       useRenderParams, NULL, isFinalCalc, 0);
+                       useRenderParams, NULL, isFinalCalc, 0, (ob->flag & OB_MODE_EDIT));
        
        if(useRenderParams || !isFinalCalc) {
                DerivedMesh *cddm= CDDM_copy(result);
@@ -111,7 +111,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
        return result;
 }
 
-static DerivedMesh *applyModifierEM(ModifierData *md, Object *UNUSED(ob),
+static DerivedMesh *applyModifierEM(ModifierData *md, Object *ob,
                                                struct EditMesh *UNUSED(editData),
                                                DerivedMesh *derivedData)
 {
@@ -119,7 +119,7 @@ static DerivedMesh *applyModifierEM(ModifierData *md, Object *UNUSED(ob),
        DerivedMesh *result;
 
        result = subsurf_make_derived_from_derived(derivedData, smd, 0,
-                       NULL, 0, 1);
+                       NULL, 0, 1, 1);
 
        return result;
 }