[Bf-blender-cvs] [e601228e010] greasepencil-object: Fix wrong color pointers for old files

Antonio Vazquez noreply at git.blender.org
Thu Apr 12 17:04:45 CEST 2018


Commit: e601228e01046db3611647329157cc0be93d49c3
Author: Antonio Vazquez
Date:   Thu Apr 12 17:03:35 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rBe601228e01046db3611647329157cc0be93d49c3

Fix wrong color pointers for old files

Some files created for Hero during development had wrong color pointers. This fix this error and avoid a segment fault.

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 91c8ed3a9ac..0a534600341 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -77,7 +77,7 @@ struct bGPDlayer *BKE_gpencil_layer_addnew(struct bGPdata *gpd, const char *name
 struct bGPdata   *BKE_gpencil_data_addnew(struct Main *bmain, const char name[]);
 
 struct bGPDframe *BKE_gpencil_frame_duplicate(const struct bGPDframe *gpf_src);
-struct bGPDframe *BKE_gpencil_frame_color_duplicate(const struct bContext *C, const struct bGPDframe *gpf_src);
+struct bGPDframe *BKE_gpencil_frame_color_duplicate(const struct bContext *C, struct bGPdata *gpd, const struct bGPDframe *gpf_src);
 struct bGPDlayer *BKE_gpencil_layer_duplicate(const struct bGPDlayer *gpl_src);
 void BKE_gpencil_frame_copy_strokes(struct bGPDframe *gpf_src, struct bGPDframe *gpf_dst);
 struct bGPDstroke *BKE_gpencil_stroke_duplicate(struct bGPDstroke *gps_src);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index ccb95e0e15f..0c02ee66c73 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -642,18 +642,21 @@ void BKE_gpencil_frame_copy_strokes(bGPDframe *gpf_src, struct bGPDframe *gpf_ds
 }
 
 /* fix any null value in palettes (this must be removed in the future) */
-static void gpencil_fix_null_palette(const bContext *C, bGPDstroke *gps_src)
+static void gpencil_fix_null_palette(const bContext *C, bGPdata *gpd, bGPDstroke *gps_src)
 {
-	bGPdata *gpd = CTX_data_gpencil_data(C);
 	Palette *tmp_palette = NULL;
-
+	printf("Fixing wrong color pointer:%s\n", gps_src->colorname);
 	tmp_palette = BKE_palette_get_active_from_context(C);
 	if (!tmp_palette) {
 		bGPDpaletteref *palslot;
 		
-		palslot = BKE_gpencil_paletteslot_addnew(CTX_data_main(C), gpd,
-			                                     "Auto-Generated Palette");
-		tmp_palette = palslot->palette;
+		if (BLI_listbase_count(&gpd->palette_slots) > 0) {
+			palslot = BLI_findlink(&gpd->palette_slots, 0);
+		}
+		else {
+			palslot = BKE_gpencil_paletteslot_addnew(CTX_data_main(C), gpd,
+				"Auto-Generated Palette");
+		}		tmp_palette = palslot->palette;
 	}
 
 	gps_src->palette = tmp_palette;
@@ -669,7 +672,7 @@ static void gpencil_fix_null_palette(const bContext *C, bGPDstroke *gps_src)
 }
 
 /* make a copy of a given gpencil frame and copy colors too */
-bGPDframe *BKE_gpencil_frame_color_duplicate(const bContext *C, const bGPDframe *gpf_src)
+bGPDframe *BKE_gpencil_frame_color_duplicate(const bContext *C, bGPdata *gpd, const bGPDframe *gpf_src)
 {
 	bGPDstroke *gps_dst;
 	bGPDframe *gpf_dst;
@@ -685,17 +688,17 @@ bGPDframe *BKE_gpencil_frame_color_duplicate(const bContext *C, const bGPDframe
 	/* copy strokes */
 	BLI_listbase_clear(&gpf_dst->strokes);
 	for (bGPDstroke *gps_src = gpf_src->strokes.first; gps_src; gps_src = gps_src->next) {
+		/* antoniov XXX: The palette never must be null, but this avoid crash after open if NULL */
+		if (gps_src->palette == NULL) {
+			gpencil_fix_null_palette(C, gpd, gps_src);
+		}
+
 		/* make copy of source stroke */
 		gps_dst = MEM_dupallocN(gps_src);
 		gps_dst->points = MEM_dupallocN(gps_src->points);
 		BKE_gpencil_stroke_weights_duplicate(gps_src, gps_dst);
 
 		gps_dst->triangles = MEM_dupallocN(gps_src->triangles);
-		/* antoniov XXX: The palette never must be null, but this avoid crash after open if NULL */
-		if (gps_src->palette == NULL) {
-			gpencil_fix_null_palette(C, gps_src);
-		}
-
 		gps_dst->palcolor = MEM_dupallocN(gps_src->palcolor);
 
 		BLI_addtail(&gpf_dst->strokes, gps_dst);
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 899d1fb7228..bd4220a50e8 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -1005,7 +1005,7 @@ void DRW_gpencil_populate_datablock(GPENCIL_e_data *e_data, void *vedata, Scene
 				BLI_ghash_remove(gpl->derived_data, ob->id.name, NULL, NULL);
 			}
 			/* create new data */
-			derived_gpf = BKE_gpencil_frame_color_duplicate(C, gpf);
+			derived_gpf = BKE_gpencil_frame_color_duplicate(C, gpd, gpf);
 			BLI_ghash_insert(gpl->derived_data, ob->id.name, derived_gpf);
 		}



More information about the Bf-blender-cvs mailing list