Commit: 2098adf2eae1b7d28e732097d5f93bf674e0328d
Author: Antonioya
Date:   Tue Aug 28 17:03:47 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB2098adf2eae1b7d28e732097d5f93bf674e0328d

Fix several things

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

M       source/blender/editors/gpencil/gpencil_edit.c
M       source/blender/editors/gpencil/gpencil_paint.c
M       source/blender/editors/object/object_relations.c
M       source/blender/gpencil_modifiers/intern/MOD_gpencilsubdiv.c

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

diff --git a/source/blender/editors/gpencil/gpencil_edit.c 
b/source/blender/editors/gpencil/gpencil_edit.c
index 299301fe4df..6f8ee35e42a 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -2958,7 +2958,9 @@ static int gp_stroke_subdivide_exec(bContext *C, 
wmOperator *op)
                                /* resize the points arrys */
                                gps->totpoints += totnewpoints;
                                gps->points = MEM_recallocN(gps->points, 
sizeof(*gps->points) * gps->totpoints);
-                               gps->dvert = MEM_recallocN(gps->dvert, 
sizeof(*gps->dvert) * gps->totpoints);
+                               if (gps->dvert != NULL) {
+                                       gps->dvert = MEM_recallocN(gps->dvert, 
sizeof(*gps->dvert) * gps->totpoints);
+                               }
 
                                gps->flag |= GP_STROKE_RECALC_CACHES;
 
@@ -2997,7 +2999,6 @@ static int gp_stroke_subdivide_exec(bContext *C, 
wmOperator *op)
                                                                }
                                                                /* Interpolate 
all values */
                                                                bGPDspoint 
*next = &temp_points[i + 1];
-                                                               MDeformVert 
*dvert_next = &temp_dverts[i + 1];
                                                                
interp_v3_v3v3(&pt_final->x, &pt->x, &next->x, 0.5f);
                                                                
pt_final->pressure = interpf(pt->pressure, next->pressure, 0.5f);
                                                                
pt_final->strength = interpf(pt->strength, next->strength, 0.5f);
@@ -3006,6 +3007,7 @@ static int gp_stroke_subdivide_exec(bContext *C, 
wmOperator *op)
                                                                pt_final->flag 
|= GP_SPOINT_SELECT;
 
                                                                if (gps->dvert 
!= NULL) {
+                                                                       
MDeformVert *dvert_next = &temp_dverts[i + 1];
                                                                        
dvert_final->totweight = dvert->totweight;
                                                                        
dvert_final->dw = MEM_dupallocN(dvert->dw);
 
diff --git a/source/blender/editors/gpencil/gpencil_paint.c 
b/source/blender/editors/gpencil/gpencil_paint.c
index 236e3d7f206..63a580337c4 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1146,7 +1146,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
                dvert = gps->dvert;
 
                /* convert all points (normal behavior) */
-               for (i = 0, ptc = gpd->runtime.sbuffer; i < 
gpd->runtime.sbuffer_size && ptc; i++, ptc++, pt++, dvert++) {
+               for (i = 0, ptc = gpd->runtime.sbuffer; i < 
gpd->runtime.sbuffer_size && ptc; i++, ptc++, pt++) {
                        /* convert screen-coordinates to appropriate 
coordinates (and store them) */
                        gp_stroke_convertcoords(p, &ptc->x, &pt->x, depth_arr ? 
depth_arr + i : NULL);
 
@@ -1161,6 +1161,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
                        if (gps->dvert != NULL) {
                                dvert->totweight = 0;
                                dvert->dw = NULL;
+                               dvert++;
                        }
                }
 
diff --git a/source/blender/editors/object/object_relations.c 
b/source/blender/editors/object/object_relations.c
index 5b9a9f97bfe..e3e41979c6d 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -799,12 +799,12 @@ bool ED_object_parent_set(ReportList *reports, const 
bContext *C, Scene *scene,
                                invert_m4_m4(ob->parentinv, workob.obmat);
                        }
                        else if (pararm && (ob->type == OB_GPENCIL) && 
(par->type == OB_ARMATURE)) {
-                               if ((partype == PAR_ARMATURE_NAME) ||
-                                       (partype == PAR_ARMATURE_ENVELOPE))
-                               {
+                               if (partype == PAR_ARMATURE_NAME) {
                                        ED_gpencil_add_armature_weights(C, 
reports, ob, par, GP_PAR_ARMATURE_NAME);
                                }
-                               else if (partype == PAR_ARMATURE_AUTO) {
+                               else if ((partype == PAR_ARMATURE_AUTO) ||
+                                       (partype == PAR_ARMATURE_ENVELOPE))
+                               {
                                        WM_cursor_wait(1);
                                        ED_gpencil_add_armature_weights(C, 
reports, ob, par, GP_PAR_ARMATURE_AUTO);
                                        WM_cursor_wait(0);
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilsubdiv.c 
b/source/blender/gpencil_modifiers/intern/MOD_gpencilsubdiv.c
index d5a372a8ba5..c3ac9840860 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilsubdiv.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilsubdiv.c
@@ -70,7 +70,10 @@ static void deformStroke(
 {
        SubdivGpencilModifierData *mmd = (SubdivGpencilModifierData *)md;
        bGPDspoint *temp_points;
-       MDeformVert *temp_dverts;
+       MDeformVert *temp_dverts = NULL;
+       MDeformVert *dvert = NULL;
+       MDeformVert *dvert_final = NULL;
+       MDeformVert *dvert_next = NULL;
        int totnewpoints, oldtotpoints;
        int i2;
 
@@ -86,16 +89,15 @@ static void deformStroke(
                totnewpoints = gps->totpoints - 1;
                /* duplicate points in a temp area */
                temp_points = MEM_dupallocN(gps->points);
-               if (gps->dvert == NULL) {
-                       gps->dvert = MEM_callocN(sizeof(MDeformVert) * 
gps->totpoints, "gp_stroke_weights");
-               }
-               temp_dverts = MEM_dupallocN(gps->dvert);
                oldtotpoints = gps->totpoints;
 
                /* resize the points arrys */
                gps->totpoints += totnewpoints;
                gps->points = MEM_recallocN(gps->points, sizeof(*gps->points) * 
gps->totpoints);
-               gps->dvert = MEM_recallocN(gps->dvert, sizeof(*gps->dvert) * 
gps->totpoints);
+               if (gps->dvert != NULL) {
+                       temp_dverts = MEM_dupallocN(gps->dvert);
+                       gps->dvert = MEM_recallocN(gps->dvert, 
sizeof(*gps->dvert) * gps->totpoints);
+               }
                gps->flag |= GP_STROKE_RECALC_CACHES;
 
                /* move points from last to first to new place */
@@ -104,30 +106,26 @@ static void deformStroke(
                        bGPDspoint *pt = &temp_points[i];
                        bGPDspoint *pt_final = &gps->points[i2];
 
-                       MDeformVert *dvert = &temp_dverts[i];
-                       MDeformVert *dvert_final = &gps->dvert[i2];
-
                        copy_v3_v3(&pt_final->x, &pt->x);
                        pt_final->pressure = pt->pressure;
                        pt_final->strength = pt->strength;
                        pt_final->time = pt->time;
                        pt_final->flag = pt->flag;
 
-                       dvert_final->totweight = dvert->totweight;
-                       dvert_final->dw = dvert->dw;
+                       if (gps->dvert != NULL) {
+                               dvert = &temp_dverts[i];
+                               dvert_final = &gps->dvert[i2];
+                               dvert_final->totweight = dvert->totweight;
+                               dvert_final->dw = dvert->dw;
+                       }
                        i2 -= 2;
                }
                /* interpolate mid points */
                i2 = 1;
                for (int i = 0; i < oldtotpoints - 1; i++) {
                        bGPDspoint *pt = &temp_points[i];
-                       MDeformVert *dvert = &temp_dverts[i];
-
                        bGPDspoint *next = &temp_points[i + 1];
-                       MDeformVert *dvert_next = &temp_dverts[i + 1];
-
                        bGPDspoint *pt_final = &gps->points[i2];
-                       MDeformVert *dvert_final = &gps->dvert[i2];
 
                        /* add a half way point */
                        interp_v3_v3v3(&pt_final->x, &pt->x, &next->x, 0.5f);
@@ -136,16 +134,22 @@ static void deformStroke(
                        CLAMP(pt_final->strength, GPENCIL_STRENGTH_MIN, 1.0f);
                        pt_final->time = interpf(pt->time, next->time, 0.5f);
 
-                       dvert_final->totweight = dvert->totweight;
-                       dvert_final->dw = MEM_dupallocN(dvert->dw);
-
-                       /* interpolate weight values */
-                       for (int d = 0; d < dvert->totweight; d++) {
-                               MDeformWeight *dw_a = &dvert->dw[d];
-                               if (dvert_next->totweight > d) {
-                                       MDeformWeight *dw_b = 
&dvert_next->dw[d];
-                                       MDeformWeight *dw_final = 
&dvert_final->dw[d];
-                                       dw_final->weight = 
interpf(dw_a->weight, dw_b->weight, 0.5f);
+                       if (gps->dvert != NULL) {
+                               dvert = &temp_dverts[i];
+                               dvert_next = &temp_dverts[i + 1];
+                               dvert_final = &gps->dvert[i2];
+
+                               dvert_final->totweight = dvert->totweight;
+                               dvert_final->dw = MEM_dupallocN(dvert->dw);
+
+                               /* interpolate weight values */
+                               for (int d = 0; d < dvert->totweight; d++) {
+                                       MDeformWeight *dw_a = &dvert->dw[d];
+                                       if (dvert_next->totweight > d) {
+                                               MDeformWeight *dw_b = 
&dvert_next->dw[d];
+                                               MDeformWeight *dw_final = 
&dvert_final->dw[d];
+                                               dw_final->weight = 
interpf(dw_a->weight, dw_b->weight, 0.5f);
+                                       }
                                }
                        }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to