Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonioya <blendergit@gmail.com>2018-08-08 17:56:56 +0300
committerAntonioya <blendergit@gmail.com>2018-08-08 17:56:56 +0300
commit5c4fd526124c348c8f324a2d0a384958c6e793b8 (patch)
tree4147a301d31e79e16a584769e61a506721a0ca6f
parent78a6fa1a7294d73a4f35b08d569d03f1afdd71ac (diff)
Fix T56220: Adding Grease Object crashes if link Material is set to Object
-rw-r--r--release/scripts/startup/bl_ui/space_view3d.py5
-rw-r--r--source/blender/blenkernel/BKE_gpencil.h1
-rw-r--r--source/blender/blenkernel/intern/gpencil.c15
-rw-r--r--source/blender/editors/gpencil/gpencil_add_monkey.c7
-rw-r--r--source/blender/editors/gpencil/gpencil_add_stroke.c7
-rw-r--r--source/blender/editors/gpencil/gpencil_brush.c4
-rw-r--r--source/blender/editors/gpencil/gpencil_data.c50
-rw-r--r--source/blender/editors/gpencil/gpencil_edit.c8
-rw-r--r--source/blender/editors/gpencil/gpencil_fill.c2
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c4
-rw-r--r--source/blender/editors/gpencil/gpencil_primitive.c2
-rw-r--r--source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c2
12 files changed, 57 insertions, 50 deletions
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 349832cedf2..72296861ad9 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -3545,9 +3545,10 @@ class VIEW3D_MT_assign_material(Menu):
def draw(self, context):
layout = self.layout
- ob = context.active_object;
+ ob = context.active_object
- for mat in ob.data.materials:
+ for slot in ob.material_slots:
+ mat = slot.material
layout.operator("gpencil.stroke_change_color", text=mat.name).material = mat.name
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 887a7f4f67b..532eaf9a0e7 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -94,6 +94,7 @@ void BKE_gpencil_frame_delete_laststroke(struct bGPDlayer *gpl, struct bGPDframe
/* materials */
void BKE_gpencil_material_index_remove(struct bGPdata *gpd, int index);
void BKE_gpencil_material_remap(struct bGPdata *gpd, const unsigned int *remap, unsigned int remap_len);
+int BKE_gpencil_get_material_index(struct Object *ob, struct Material *ma);
/* statistics functions */
void BKE_gpencil_stats_update(struct bGPdata *gpd);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index b619304d39b..140e4a25882 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1630,3 +1630,18 @@ void BKE_gpencil_stats_update(bGPdata *gpd)
}
}
+
+/* get material index */
+int BKE_gpencil_get_material_index(Object *ob, Material *ma)
+{
+ short *totcol = give_totcolp(ob);
+ Material *read_ma = NULL;
+ for (short i = 0; i < *totcol; i++) {
+ read_ma = give_current_material(ob, i + 1);
+ if (ma == read_ma) {
+ return i + 1;
+ }
+ }
+
+ return 0;
+}
diff --git a/source/blender/editors/gpencil/gpencil_add_monkey.c b/source/blender/editors/gpencil/gpencil_add_monkey.c
index b0c3675c123..78286e3f672 100644
--- a/source/blender/editors/gpencil/gpencil_add_monkey.c
+++ b/source/blender/editors/gpencil/gpencil_add_monkey.c
@@ -55,11 +55,10 @@ typedef struct ColorTemplate {
/* Add color an ensure duplications (matched by name) */
static int gpencil_monkey_color(Main *bmain, Object *ob, const ColorTemplate *pct)
{
- Material *ma = NULL;
- Material ***matar = give_matarar(ob);
short *totcol = give_totcolp(ob);
+ Material *ma = NULL;
for (short i = 0; i < *totcol; i++) {
- ma = (*matar)[i];
+ ma = give_current_material(ob, i + 1);
if (STREQ(ma->id.name, pct->name)) {
return i;
}
@@ -73,7 +72,7 @@ static int gpencil_monkey_color(Main *bmain, Object *ob, const ColorTemplate *pc
copy_v4_v4(ma->gp_style->stroke_rgba, pct->line);
copy_v4_v4(ma->gp_style->fill_rgba, pct->fill);
- return BKE_object_material_slot_find_index(ob, ma) - 1;
+ return BKE_gpencil_get_material_index(ob, ma) - 1;
}
/* ***************************************************************** */
diff --git a/source/blender/editors/gpencil/gpencil_add_stroke.c b/source/blender/editors/gpencil/gpencil_add_stroke.c
index f932f98ac1d..c5020593bcb 100644
--- a/source/blender/editors/gpencil/gpencil_add_stroke.c
+++ b/source/blender/editors/gpencil/gpencil_add_stroke.c
@@ -55,11 +55,10 @@ typedef struct ColorTemplate {
/* Add color an ensure duplications (matched by name) */
static int gp_stroke_material(Main *bmain, Object *ob, const ColorTemplate *pct)
{
- Material *ma = NULL;
- Material ***matar = give_matarar(ob);
short *totcol = give_totcolp(ob);
+ Material *ma = NULL;
for (short i = 0; i < *totcol; i++) {
- ma = (*matar)[i];
+ ma = give_current_material(ob, i + 1);
if (STREQ(ma->id.name, pct->name)) {
return i;
}
@@ -73,7 +72,7 @@ static int gp_stroke_material(Main *bmain, Object *ob, const ColorTemplate *pct)
copy_v4_v4(ma->gp_style->stroke_rgba, pct->line);
copy_v4_v4(ma->gp_style->fill_rgba, pct->fill);
- return BKE_object_material_slot_find_index(ob, ma) - 1;
+ return BKE_gpencil_get_material_index(ob, ma) - 1;
}
/* ***************************************************************** */
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index ff93e7fc57d..d8be0dd665a 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -1053,8 +1053,8 @@ static void gp_brush_clone_add(bContext *C, tGP_BrushEditData *gso)
/* Fix color references */
Material *ma = BLI_ghash_lookup(data->new_colors, &new_stroke->mat_nr);
- if ((ma) && (BKE_object_material_slot_find_index(ob, ma) > 0)) {
- gps->mat_nr = BKE_object_material_slot_find_index(ob, ma) - 1;
+ 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);
}
else {
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 43721d73a80..faeee4db169 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -1150,8 +1150,8 @@ static int gp_stroke_change_color_exec(bContext *C, wmOperator *op)
}
}
/* try to find slot */
- int idx = BKE_object_material_slot_find_index(ob, ma) - 1;
- if (idx == 0) {
+ int idx = BKE_gpencil_get_material_index(ob, ma) - 1;
+ if (idx <= 0) {
return OPERATOR_CANCELLED;
}
@@ -1230,7 +1230,6 @@ static int gp_stroke_lock_color_exec(bContext *C, wmOperator *UNUSED(op))
Object *ob = CTX_data_active_object(C);
- Material ***matar = give_matarar(ob);
short *totcol = give_totcolp(ob);
/* sanity checks */
@@ -1239,9 +1238,8 @@ static int gp_stroke_lock_color_exec(bContext *C, wmOperator *UNUSED(op))
/* first lock all colors */
for (short i = 0; i < *totcol; i++) {
- Material *tmp_ma = (*matar)[i];
+ Material *tmp_ma = give_current_material(ob, i + 1);
tmp_ma->gp_style->flag |= GP_STYLE_COLOR_LOCKED;
-
}
/* loop all selected strokes and unlock any color */
@@ -1256,7 +1254,8 @@ static int gp_stroke_lock_color_exec(bContext *C, wmOperator *UNUSED(op))
continue;
}
/* unlock color */
- Material *tmp_ma = (*matar)[gps->mat_nr];
+ Material *tmp_ma = give_current_material(ob, gps->mat_nr + 1);
+
tmp_ma->gp_style->flag &= ~GP_STYLE_COLOR_LOCKED;
}
}
@@ -1896,12 +1895,11 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op)
obact->actdef = 1;
/* add missing materials reading source materials and checking in destination object */
- Material ***matar = give_matarar(ob_src);
short *totcol = give_totcolp(ob_src);
for (short i = 0; i < *totcol; i++) {
- Material *tmp_ma = (*matar)[i];
- if (BKE_object_material_slot_find_index(ob_dst, tmp_ma) == 0) {
+ Material *tmp_ma = give_current_material(ob_src, i + 1);
+ if (BKE_gpencil_get_material_index(ob_dst, tmp_ma) == 0) {
BKE_object_material_slot_add(bmain, ob_dst);
assign_material(bmain, ob_dst, tmp_ma, ob_dst->totcol, BKE_MAT_ASSIGN_USERPREF);
}
@@ -1941,7 +1939,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op)
/* reasign material. Look old material and try to find in dst */
ma_src = give_current_material(ob_src, gps->mat_nr + 1);
if (ma_src != NULL) {
- idx = BKE_object_material_slot_find_index(ob_dst, ma_src);
+ idx = BKE_gpencil_get_material_index(ob_dst, ma_src);
if (idx > 0) {
gps->mat_nr = idx - 1;
}
@@ -2041,13 +2039,12 @@ static int gpencil_lock_layer_exec(bContext *C, wmOperator *UNUSED(op))
/* first lock and hide all colors */
Material *ma = NULL;
- Material ***matar = give_matarar(ob);
short *totcol = give_totcolp(ob);
- if ((totcol == 0) || (matar == NULL))
+ if (totcol == 0)
return OPERATOR_CANCELLED;
for (short i = 0; i < *totcol; i++) {
- ma = (*matar)[i];
+ ma = give_current_material(ob, i + 1);
gp_style = ma->gp_style;
gp_style->flag |= GP_STYLE_COLOR_LOCKED;
gp_style->flag |= GP_STYLE_COLOR_HIDE;
@@ -2113,10 +2110,9 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op)
/* Test whether to isolate or clear all flags */
Material *ma = NULL;
- Material ***matar = give_matarar(ob);
short *totcol = give_totcolp(ob);
for (short i = 0; i < *totcol; i++) {
- ma = (*matar)[i];
+ ma = give_current_material(ob, i + 1);
/* Skip if this is the active one */
if (ma == active_ma)
continue;
@@ -2135,7 +2131,7 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op)
if (isolate) {
/* Set flags on all "other" colors */
for (short i = 0; i < *totcol; i++) {
- ma = (*matar)[i];
+ ma = give_current_material(ob, i + 1);
gp_style = ma->gp_style;
if (gp_style == active_color)
continue;
@@ -2146,7 +2142,7 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op)
else {
/* Clear flags - Restore everything else */
for (short i = 0; i < *totcol; i++) {
- ma = (*matar)[i];
+ ma = give_current_material(ob, i + 1);
gp_style = ma->gp_style;
gp_style->flag &= ~flags;
}
@@ -2188,16 +2184,15 @@ static int gpencil_color_hide_exec(bContext *C, wmOperator *op)
bool unselected = RNA_boolean_get(op->ptr, "unselected");
Material *ma = NULL;
- Material ***matar = give_matarar(ob);
short *totcol = give_totcolp(ob);
- if ((totcol == 0) || (matar == NULL))
+ if (totcol == 0)
return OPERATOR_CANCELLED;
if (unselected) {
/* hide unselected */
MaterialGPencilStyle *color = NULL;
for (short i = 0; i < *totcol; i++) {
- ma = (*matar)[i];
+ ma = give_current_material(ob, i + 1);
color = ma->gp_style;
if (active_color != color) {
color->flag |= GP_STYLE_COLOR_HIDE;
@@ -2239,17 +2234,16 @@ static int gpencil_color_reveal_exec(bContext *C, wmOperator *UNUSED(op))
{
Object *ob = CTX_data_active_object(C);
Material *ma = NULL;
- Material ***matar = give_matarar(ob);
short *totcol = give_totcolp(ob);
- if ((totcol == 0) || (matar == NULL))
+ if (totcol == 0)
return OPERATOR_CANCELLED;
/* make all colors visible */
MaterialGPencilStyle *gp_style = NULL;
for (short i = 0; i < *totcol; i++) {
- ma = (*matar)[i];
+ ma = give_current_material(ob, i + 1);
gp_style = ma->gp_style;
gp_style->flag &= ~GP_STYLE_COLOR_HIDE;
}
@@ -2282,17 +2276,16 @@ static int gpencil_color_lock_all_exec(bContext *C, wmOperator *UNUSED(op))
Object *ob = CTX_data_active_object(C);
Material *ma = NULL;
- Material ***matar = give_matarar(ob);
short *totcol = give_totcolp(ob);
- if ((totcol == 0) || (matar == NULL))
+ if (totcol == 0)
return OPERATOR_CANCELLED;
/* make all layers non-editable */
MaterialGPencilStyle *gp_style = NULL;
for (short i = 0; i < *totcol; i++) {
- ma = (*matar)[i];
+ ma = give_current_material(ob, i + 1);
gp_style = ma->gp_style;
gp_style->flag |= GP_STYLE_COLOR_LOCKED;
}
@@ -2324,17 +2317,16 @@ static int gpencil_color_unlock_all_exec(bContext *C, wmOperator *UNUSED(op))
{
Object *ob = CTX_data_active_object(C);
Material *ma = NULL;
- Material ***matar = give_matarar(ob);
short *totcol = give_totcolp(ob);
- if ((totcol == 0) || (matar == NULL))
+ if (totcol == 0)
return OPERATOR_CANCELLED;
/* make all layers editable again*/
MaterialGPencilStyle *gp_style = NULL;
for (short i = 0; i < *totcol; i++) {
- ma = (*matar)[i];
+ ma = give_current_material(ob, i + 1);
gp_style = ma->gp_style;
gp_style->flag &= ~GP_STYLE_COLOR_LOCKED;
}
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 969ff326c61..f7c08239647 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -732,7 +732,7 @@ GHash *gp_copybuf_validate_colormap(bContext *C)
int *key = BLI_ghashIterator_getKey(&gh_iter);
Material *ma = BLI_ghashIterator_getValue(&gh_iter);
- if (BKE_object_material_slot_find_index(ob, ma) == 0) {
+ if (BKE_gpencil_get_material_index(ob, ma) == 0) {
BKE_object_material_slot_add(bmain, ob);
assign_material(bmain, ob, ma, ob->totcol, BKE_MAT_ASSIGN_USERPREF);
}
@@ -980,8 +980,8 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op)
/* Remap material */
Material *ma = BLI_ghash_lookup(new_colors, &new_stroke->mat_nr);
- if ((ma) && (BKE_object_material_slot_find_index(ob, ma) > 0)) {
- gps->mat_nr = BKE_object_material_slot_find_index(ob, ma) - 1;
+ 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);
}
else {
@@ -3184,7 +3184,7 @@ static int gp_stroke_separate_exec(bContext *C, wmOperator *op)
/* add duplicate materials */
ma = give_current_material(ob, gps->mat_nr + 1);
- idx = BKE_object_material_slot_find_index(ob_dst, ma);
+ idx = BKE_gpencil_get_material_index(ob_dst, ma);
if (idx == 0) {
totadd++;
diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index ec90c826a27..c6df07ae83e 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -841,7 +841,7 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
gps->flag |= GP_STROKE_CYCLIC;
gps->flag |= GP_STROKE_3DSPACE;
- gps->mat_nr = BKE_object_material_slot_find_index(tgpf->ob, tgpf->mat) - 1;
+ gps->mat_nr = BKE_gpencil_get_material_index(tgpf->ob, tgpf->mat) - 1;
/* allocate memory for storage points */
gps->totpoints = tgpf->sbuffer_size;
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 88f90d6c128..d4371926eb4 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1150,7 +1150,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
}
/* Save material index */
- gps->mat_nr = BKE_object_material_slot_find_index(p->ob, p->material) - 1;
+ gps->mat_nr = BKE_gpencil_get_material_index(p->ob, p->material) - 1;
/* calculate UVs along the stroke */
ED_gpencil_calc_stroke_uv(obact, gps);
@@ -1602,7 +1602,7 @@ static void gp_init_colors(tGPsdata *p)
}
/* check if the material is already on object material slots and add it if missing */
- if (BKE_object_material_slot_find_index(p->ob, p->material) == 0) {
+ if (BKE_gpencil_get_material_index(p->ob, p->material) == 0) {
BKE_object_material_slot_add(p->bmain, p->ob);
assign_material(p->bmain, p->ob, ma, p->ob->totcol, BKE_MAT_ASSIGN_USERPREF);
}
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 9dbec666cc4..2dfdeeba0b6 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -177,7 +177,7 @@ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
gps->flag |= GP_STROKE_CYCLIC;
gps->flag |= GP_STROKE_3DSPACE;
- gps->mat_nr = BKE_object_material_slot_find_index(tgpi->ob, tgpi->mat) - 1;
+ gps->mat_nr = BKE_gpencil_get_material_index(tgpi->ob, tgpi->mat) - 1;
/* allocate memory for storage points, but keep empty */
gps->totpoints = 0;
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
index 21a55e3f970..151218c06e4 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
@@ -169,7 +169,7 @@ void gpencil_apply_modifier_material(
DEG_id_tag_update(&newmat->id, DEG_TAG_COPY_ON_WRITE);
}
/* reasign color index */
- int idx = BKE_object_material_slot_find_index(ob, newmat);
+ int idx = BKE_gpencil_get_material_index(ob, newmat);
gps->mat_nr = idx - 1;
}
else {