fix regression in 2.68 [#36240] Painting Undo Enable Face paint Crash
authorCampbell Barton <ideasman42@gmail.com>
Mon, 22 Jul 2013 18:19:02 +0000 (18:19 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 22 Jul 2013 18:19:02 +0000 (18:19 +0000)
source/blender/editors/sculpt_paint/paint_image_proj.c

index 017232d18569421674f76839780fbd95937a3115..db55dc271f1f8d6a64d8e3a6c81b84b4d92dbfce 100644 (file)
@@ -2816,7 +2816,11 @@ static void project_paint_begin(ProjPaintState *ps)
 
        int a, i; /* generic looping vars */
        int image_index = -1, face_index;
-       int *mpoly_origindex;
+
+       /* double lookup */
+       const int *index_mf_to_mpoly = NULL;
+       const int *index_mp_to_orig  = NULL;
+
        MVert *mv;
 
        MemArena *arena; /* at the moment this is just ps->arena_mt[0], but use this to show were not multithreading */
@@ -2871,12 +2875,17 @@ static void project_paint_begin(ProjPaintState *ps)
        ps->dm_totface = ps->dm->getNumTessFaces(ps->dm);
 
        if (ps->do_face_sel) {
-               mpoly_orig = ((Mesh *)ps->ob->data)->mpoly;
-               mpoly_origindex = ps->dm->getPolyDataArray(ps->dm, CD_ORIGINDEX);
+               index_mf_to_mpoly = ps->dm->getTessFaceDataArray(ps->dm, CD_ORIGINDEX);
+               index_mp_to_orig  = ps->dm->getPolyDataArray(ps->dm, CD_ORIGINDEX);
+               if (index_mf_to_mpoly == NULL) {
+                       index_mp_to_orig = NULL;
+               }
+               else {
+                       mpoly_orig = ((Mesh *)ps->ob->data)->mpoly;
+               }
        }
        else {
                mpoly_orig = NULL;
-               mpoly_origindex = NULL;
        }
 
        /* use clone mtface? */
@@ -3166,8 +3175,10 @@ static void project_paint_begin(ProjPaintState *ps)
 
                if (ps->do_face_sel) {
                        int orig_index;
-                       if (mpoly_origindex && ((orig_index = mpoly_origindex[face_index])) != ORIGINDEX_NONE) {
-                               MPoly *mp = mpoly_orig + orig_index;
+                       if (index_mp_to_orig && ((orig_index = DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig,
+                                                                                       face_index))) != ORIGINDEX_NONE)
+                       {
+                               MPoly *mp = &mpoly_orig[orig_index];
                                is_face_sel = ((mp->flag & ME_FACE_SEL) != 0);
                        }
                        else {