[Bf-blender-cvs] [b1fa2a8fbbd] master: Fix T59826: grease pencil crash with empty material slot.
Brecht Van Lommel
noreply at git.blender.org
Tue Jan 15 18:54:28 CET 2019
Commit: b1fa2a8fbbd9d17da7e1fea8afd29055f47113c8
Author: Brecht Van Lommel
Date: Tue Jan 15 18:17:53 2019 +0100
Branches: master
https://developer.blender.org/rBb1fa2a8fbbd9d17da7e1fea8afd29055f47113c8
Fix T59826: grease pencil crash with empty material slot.
===================================================================
M release/scripts/startup/bl_ui/space_view3d.py
M source/blender/editors/gpencil/drawgpencil.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 5c2cf8d529f..a6002dfaad4 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -3892,7 +3892,8 @@ class VIEW3D_MT_assign_material(Menu):
for slot in ob.material_slots:
mat = slot.material
- layout.operator("gpencil.stroke_change_color", text=mat.name).material = mat.name
+ if mat:
+ layout.operator("gpencil.stroke_change_color", text=mat.name).material = mat.name
class VIEW3D_MT_gpencil_copy_layer(Menu):
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 72660c90837..548ccac7de3 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -602,7 +602,7 @@ static void gp_draw_stroke_fill(
{
BLI_assert(gps->totpoints >= 3);
Material *ma = gpd->mat[gps->mat_nr];
- MaterialGPencilStyle *gp_style = ma->gp_style;
+ MaterialGPencilStyle *gp_style = (ma) ? ma->gp_style : NULL;
/* Calculate triangles cache for filling area (must be done only after changes) */
if ((gps->flag & GP_STROKE_RECALC_GEOMETRY) || (gps->tot_triangles == 0) || (gps->triangles == NULL)) {
@@ -1013,7 +1013,7 @@ static void gp_draw_strokes(tGPDdraw *tgpw)
}
/* check if the color is visible */
Material *ma = tgpw->gpd->mat[gps->mat_nr];
- MaterialGPencilStyle *gp_style = ma->gp_style;
+ MaterialGPencilStyle *gp_style = (ma) ? ma->gp_style : NULL;
if ((gp_style == NULL) ||
(gp_style->flag & GP_STYLE_COLOR_HIDE) ||
@@ -1233,7 +1233,7 @@ static void gp_draw_strokes_edit(
/* verify color lock */
{
Material *ma = gpd->mat[gps->mat_nr];
- MaterialGPencilStyle *gp_style = ma->gp_style;
+ MaterialGPencilStyle *gp_style = (ma) ? ma->gp_style : NULL;
if (gp_style != NULL) {
if (gp_style->flag & GP_STYLE_COLOR_HIDE) {
@@ -1263,7 +1263,7 @@ static void gp_draw_strokes_edit(
/* for now, we assume that the base color of the points is not too close to the real color */
/* set color using material */
Material *ma = gpd->mat[gps->mat_nr];
- MaterialGPencilStyle *gp_style = ma->gp_style;
+ MaterialGPencilStyle *gp_style = (ma) ? ma->gp_style : NULL;
float selectColor[4];
UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, selectColor);
@@ -1307,10 +1307,14 @@ static void gp_draw_strokes_edit(
immAttr3fv(color, selectColor);
immAttr1f(size, vsize);
}
- else {
+ else if (gp_style) {
immAttr3fv(color, gp_style->stroke_rgba);
immAttr1f(size, bsize);
}
+ else {
+ immAttr3f(color, 0.0f, 0.0f, 0.0f);
+ immAttr1f(size, bsize);
+ }
/* then position */
if (gps->flag & GP_STROKE_3DSPACE) {
More information about the Bf-blender-cvs
mailing list