diff --git a/release/scripts/startup/bl_ui/properties_freestyle.py b/release/scripts/startup/bl_ui/properties_freestyle.py index 18dd8f591e8..a96441a26e5 100644 --- a/release/scripts/startup/bl_ui/properties_freestyle.py +++ b/release/scripts/startup/bl_ui/properties_freestyle.py @@ -530,6 +530,8 @@ class RENDERLAYER_PT_freestyle_linestyle(RenderLayerFreestyleEditorButtonsPanel, linestyle = lineset.linestyle layout.template_ID(lineset, "linestyle", new="scene.freestyle_linestyle_new") + if linestyle is None: + return row = layout.row(align=True) row.prop(linestyle, "panel", expand=True) if linestyle.panel == 'STROKES': diff --git a/source/blender/blenkernel/intern/freestyle.c b/source/blender/blenkernel/intern/freestyle.c index 846b3779649..d87c93310c8 100644 --- a/source/blender/blenkernel/intern/freestyle.c +++ b/source/blender/blenkernel/intern/freestyle.c @@ -107,7 +107,7 @@ void BKE_freestyle_config_copy(FreestyleConfig *new_config, FreestyleConfig *con static void copy_lineset(FreestyleLineSet *new_lineset, FreestyleLineSet *lineset) { new_lineset->linestyle = lineset->linestyle; - if (lineset->linestyle) + if (new_lineset->linestyle) new_lineset->linestyle->id.us++; new_lineset->flags = lineset->flags; new_lineset->selection = lineset->selection; diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index 58c244228ed..c19c5a38517 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -860,8 +860,12 @@ static int freestyle_linestyle_new_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_ERROR, "No active lineset to add a new line style to"); return OPERATOR_CANCELLED; } - lineset->linestyle->id.us--; - lineset->linestyle = BKE_copy_linestyle(lineset->linestyle); + if (lineset->linestyle) { + lineset->linestyle->id.us--; + lineset->linestyle = BKE_copy_linestyle(lineset->linestyle); + } else { + lineset->linestyle = BKE_new_linestyle("LineStyle", NULL); + } WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene); @@ -894,6 +898,10 @@ static int freestyle_color_modifier_add_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style to add the modifier to"); return OPERATOR_CANCELLED; } + if (!lineset->linestyle) { + BKE_report(op->reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)"); + return OPERATOR_CANCELLED; + } if (BKE_add_linestyle_color_modifier(lineset->linestyle, type) == NULL) { BKE_report(op->reports, RPT_ERROR, "Unknown line color modifier type"); return OPERATOR_CANCELLED; @@ -933,6 +941,10 @@ static int freestyle_alpha_modifier_add_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style to add the modifier to"); return OPERATOR_CANCELLED; } + if (!lineset->linestyle) { + BKE_report(op->reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)"); + return OPERATOR_CANCELLED; + } if (BKE_add_linestyle_alpha_modifier(lineset->linestyle, type) == NULL) { BKE_report(op->reports, RPT_ERROR, "Unknown alpha transparency modifier type"); return OPERATOR_CANCELLED; @@ -972,6 +984,10 @@ static int freestyle_thickness_modifier_add_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style to add the modifier to"); return OPERATOR_CANCELLED; } + if (!lineset->linestyle) { + BKE_report(op->reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)"); + return OPERATOR_CANCELLED; + } if (BKE_add_linestyle_thickness_modifier(lineset->linestyle, type) == NULL) { BKE_report(op->reports, RPT_ERROR, "Unknown line thickness modifier type"); return OPERATOR_CANCELLED; @@ -1011,6 +1027,10 @@ static int freestyle_geometry_modifier_add_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style to add the modifier to"); return OPERATOR_CANCELLED; } + if (!lineset->linestyle) { + BKE_report(op->reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)"); + return OPERATOR_CANCELLED; + } if (BKE_add_linestyle_geometry_modifier(lineset->linestyle, type) == NULL) { BKE_report(op->reports, RPT_ERROR, "Unknown stroke geometry modifier type"); return OPERATOR_CANCELLED; @@ -1064,6 +1084,10 @@ static int freestyle_modifier_remove_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style the modifier belongs to"); return OPERATOR_CANCELLED; } + if (!lineset->linestyle) { + BKE_report(op->reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)"); + return OPERATOR_CANCELLED; + } switch (freestyle_get_modifier_type(&ptr)) { case LS_MODIFIER_TYPE_COLOR: @@ -1114,6 +1138,10 @@ static int freestyle_modifier_copy_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style the modifier belongs to"); return OPERATOR_CANCELLED; } + if (!lineset->linestyle) { + BKE_report(op->reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)"); + return OPERATOR_CANCELLED; + } switch (freestyle_get_modifier_type(&ptr)) { case LS_MODIFIER_TYPE_COLOR: @@ -1165,6 +1193,10 @@ static int freestyle_modifier_move_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_ERROR, "No active lineset and associated line style the modifier belongs to"); return OPERATOR_CANCELLED; } + if (!lineset->linestyle) { + BKE_report(op->reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)"); + return OPERATOR_CANCELLED; + } switch (freestyle_get_modifier_type(&ptr)) { case LS_MODIFIER_TYPE_COLOR: diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index f1a05700bd9..0cfb399c470 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -1541,7 +1541,8 @@ static void rna_FreestyleLineSet_linestyle_set(PointerRNA *ptr, PointerRNA value { FreestyleLineSet *lineset = (FreestyleLineSet *)ptr->data; - lineset->linestyle->id.us--; + if (lineset->linestyle) + lineset->linestyle->id.us--; lineset->linestyle = (FreestyleLineStyle *)value.data; lineset->linestyle->id.us++; }