GPencil: Create new set of brushes for Win32 damaged files when use primitives
authorAntonio Vazquez <blendergit@gmail.com>
Wed, 5 Jun 2019 07:57:21 +0000 (09:57 +0200)
committerAntonio Vazquez <blendergit@gmail.com>
Wed, 5 Jun 2019 07:57:21 +0000 (09:57 +0200)
Some old Win32 files could have the brushes damaged and this produces a segment fault. Now, if the brush is damaged, a new set of brushes is created.

Related to T61413

source/blender/editors/gpencil/gpencil_primitive.c

index bff17bf5078a0299376d9dbd9c5115cbc450dc19..d6497e6e58e413dac0b9cbb79d2b560baac3f4bd 100644 (file)
@@ -305,21 +305,11 @@ static void gpencil_primitive_allocate_memory(tGPDprimitive *tgpi)
 /* Helper: Create internal strokes primitives data */
 static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
 {
-  ToolSettings *ts = CTX_data_tool_settings(C);
   Depsgraph *depsgraph = CTX_data_depsgraph(C);
   int cfra_eval = (int)DEG_get_ctime(depsgraph);
 
   bGPDlayer *gpl = CTX_data_active_gpencil_layer(C);
 
-  /* if brush doesn't exist, create a new one */
-  Paint *paint = &ts->gp_paint->paint;
-  /* if not exist, create a new one */
-  if ((paint->brush == NULL) || (paint->brush->gpencil_settings == NULL)) {
-    /* create new brushes */
-    BKE_brush_gpencil_presets(C);
-  }
-  tgpi->brush = paint->brush;
-
   /* if layer doesn't exist, create a new one */
   if (gpl == NULL) {
     gpl = BKE_gpencil_layer_addnew(tgpi->gpd, DATA_("Primitives"), true);
@@ -1106,6 +1096,8 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op)
   Main *bmain = CTX_data_main(C);
   Scene *scene = CTX_data_scene(C);
   Depsgraph *depsgraph = CTX_data_depsgraph(C);
+  Paint *paint = &ts->gp_paint->paint;
+
   int cfra_eval = (int)DEG_get_ctime(depsgraph);
 
   /* create temporary operator data */
@@ -1136,6 +1128,12 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op)
   /* region where paint was originated */
   tgpi->gpd->runtime.ar = tgpi->ar;
 
+  /* if brush doesn't exist, create a new set (fix damaged files from old versions) */
+  if ((paint->brush == NULL) || (paint->brush->gpencil_settings == NULL)) {
+    BKE_brush_gpencil_presets(C);
+  }
+  tgpi->brush = paint->brush;
+
   /* control points */
   tgpi->gpd->runtime.cp_points = MEM_callocN(sizeof(bGPDcontrolpoint) * MAX_CP,
                                              "gp primitive cpoint");