recent fix for #31581 could crash when doing edge slide on a mesh with no UV's.
authorCampbell Barton <ideasman42@gmail.com>
Thu, 28 Jun 2012 14:18:04 +0000 (14:18 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 28 Jun 2012 14:18:04 +0000 (14:18 +0000)
source/blender/editors/transform/transform.c

index 4dee3514142bc380fa1b56103567c180d206c6fc..928b9c2fc628b50a73fe2ba4ff247076501e8a70 100644 (file)
@@ -4992,6 +4992,7 @@ void projectSVData(TransInfo *t, int final)
        BMEditMesh *em = sld->em;
        SmallHash visit;
        int i;
+       short has_uv;
 
        if (!em)
                return;
@@ -5004,6 +5005,8 @@ void projectSVData(TransInfo *t, int final)
        if (em->bm->shapenr > 1)
                return;
 
+       has_uv = CustomData_has_layer(&(em->bm->ldata), CD_MLOOPUV);
+
        BLI_smallhash_init(&visit);
        
        for (i = 0, sv = sld->sv; i < sld->totsv; sv++, i++) {
@@ -5011,8 +5014,6 @@ void projectSVData(TransInfo *t, int final)
                BMFace *f;
                BMIter liter_v;
                BMLoop *l_v;
-               float uv_med[2] = {0.0, 0.0};
-               int tot_loops = 0;
                
                /* BMESH_TODO, this interpolates between vertex/loops which are not moved
                 * (are only apart of a face attached to a slide vert), couldn't we iterate BM_LOOPS_OF_VERT
@@ -5141,17 +5142,22 @@ void projectSVData(TransInfo *t, int final)
 
                /* make sure every loop of the vertex has identical uv data. Use this temporarily to
                 * fix #31581 until proper data correction/ support for islands is done */
-               BM_ITER_ELEM (l_v, &liter_v, sv->v, BM_LOOPS_OF_VERT) {
-                       MLoopUV *uv = CustomData_bmesh_get(&em->bm->ldata, l_v->head.data, CD_MLOOPUV);
-                       add_v2_v2(uv_med, uv->uv);
-                       tot_loops++;
-               }
+               /* XXX - this only does the active UV layer which is not really good, should do _all_ uv's - campbell */
+               if (has_uv) {
+                       float uv_med[2] = {0.0, 0.0};
+                       int tot_loops = 0;
+                       BM_ITER_ELEM (l_v, &liter_v, sv->v, BM_LOOPS_OF_VERT) {
+                               MLoopUV *uv = CustomData_bmesh_get(&em->bm->ldata, l_v->head.data, CD_MLOOPUV);
+                               add_v2_v2(uv_med, uv->uv);
+                               tot_loops++;
+                       }
 
-               mul_v2_fl(uv_med, 1.0/tot_loops);
+                       mul_v2_fl(uv_med, 1.0/tot_loops);
 
-               BM_ITER_ELEM (l_v, &liter_v, sv->v, BM_LOOPS_OF_VERT) {
-                       MLoopUV *uv = CustomData_bmesh_get(&em->bm->ldata, l_v->head.data, CD_MLOOPUV);
-                       copy_v2_v2(uv->uv, uv_med);
+                       BM_ITER_ELEM (l_v, &liter_v, sv->v, BM_LOOPS_OF_VERT) {
+                               MLoopUV *uv = CustomData_bmesh_get(&em->bm->ldata, l_v->head.data, CD_MLOOPUV);
+                               copy_v2_v2(uv->uv, uv_med);
+                       }
                }
        }