Fix T59579: Grease Pencil copy buffer loses material information
authorAntonioya <blendergit@gmail.com>
Wed, 19 Dec 2018 21:56:29 +0000 (22:56 +0100)
committerAntonioya <blendergit@gmail.com>
Wed, 19 Dec 2018 21:57:03 +0000 (22:57 +0100)
source/blender/editors/gpencil/gpencil_edit.c

index 916a268dc57a5250f5f16562e614348e4ea044cc..5cfc35d122adcde38697716aa1a5ed93cd56f417 100644 (file)
@@ -871,7 +871,9 @@ GHash *gp_copybuf_validate_colormap(bContext *C)
                }
 
                /* Store this mapping (for use later when pasting) */
-               BLI_ghash_insert(new_colors, key, ma);
+               if (!BLI_ghash_haskey(new_colors, POINTER_FROM_INT(*key))) {
+                       BLI_ghash_insert(new_colors, POINTER_FROM_INT(*key), ma);
+               }
        }
 
        gp_strokes_copypastebuf_colors_name_to_material_free(name_to_ma);
@@ -1118,13 +1120,13 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op)
                                BLI_addtail(&gpf->strokes, new_stroke);
 
                                /* Remap material */
-                               Material *ma = BLI_ghash_lookup(new_colors, &new_stroke->mat_nr);
+                               Material *ma = BLI_ghash_lookup(new_colors, POINTER_FROM_INT(new_stroke->mat_nr));
                                if ((ma) && (BKE_gpencil_get_material_index(ob, ma) > 0)) {
-                                       gps->mat_nr = BKE_gpencil_get_material_index(ob, ma) - 1;
-                                       CLAMP_MIN(gps->mat_nr, 0);
+                                       new_stroke->mat_nr = BKE_gpencil_get_material_index(ob, ma) - 1;
+                                       CLAMP_MIN(new_stroke->mat_nr, 0);
                                }
                                else {
-                                       gps->mat_nr = 0; /* only if the color is not found */
+                                       new_stroke->mat_nr = 0; /* only if the color is not found */
                                }
 
                        }