Fix T59826: grease pencil crash with empty material slot.

This commit is contained in:
Brecht Van Lommel 2019-01-15 18:17:53 +01:00
parent eb61e6840e
commit b1fa2a8fbb
Notes: blender-bot 2023-02-14 07:53:51 +01:00
Referenced by issue #59826, Suddenly crash when using the fill tool when a key frames are selected
2 changed files with 11 additions and 6 deletions

View File

@ -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):

View File

@ -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) {