GP: Fix unreported segment fault with some old files

In some corner situations for old files, the weights array could not be initialized properly.
This commit is contained in:
Antonioya
2018-08-08 12:17:00 +02:00
parent 6a07818e8f
commit 08e49c034b

View File

@@ -257,6 +257,11 @@ void BKE_gpencil_simplify_stroke(bGPDstroke *gps, float factor)
/* first create temp data and convert points to 2D */
vec2f *points2d = MEM_mallocN(sizeof(vec2f) * gps->totpoints, "GP Stroke temp 2d points");
/* for some old files, the weights array could not be initializated */
if (gps->dvert == NULL) {
gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
}
gpencil_stroke_project_2d(gps->points, gps->totpoints, points2d);
gpencil_rdp_stroke(gps, points2d, factor);
@@ -271,6 +276,11 @@ void BKE_gpencil_simplify_fixed(bGPDstroke *gps)
return;
}
/* for some old files, the weights array could not be initializated */
if (gps->dvert == NULL) {
gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
}
/* save points */
bGPDspoint *old_points = MEM_dupallocN(gps->points);
MDeformVert *old_dvert = MEM_dupallocN(gps->dvert);