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:
authorPhilipp Oeser <info@graphics-engineer.com>2021-03-31 16:54:41 +0300
committerPhilipp Oeser <info@graphics-engineer.com>2021-04-02 22:23:37 +0300
commite0a07700bfbe3a4d64e65d0d51adb8c44ef105d7 (patch)
treee145d87728d7e95e79d05ba1bf94d67cf3b368f5 /source/blender/gpencil_modifiers
parentfcc3227efd837de2733dd79d9f8baf9c3b6d01a8 (diff)
GPencil: Prevent RNA assignment of invalid materials in modifiers
Materials used in grease pencil modifiers have the requirement that they are already used on the object. In the UI dropdown, this restriction is ensured by calling uiItemPointerR with appropriate searchptr and searchpropname, so only giving the user the choice of materials already used on the object. From python though, it was still possible to assign materials outside of this this restriction. This led to reports like T86981 [which have been partially solved by clamping the material index in the modifier code to be in the valid range]. Now make sure we dont assign "invalid" materials through RNA by appropriate RNA pointer functions. This also adds a proper warning (red, alert) in case of the LineArt modifier if such a invalid material is still in the file [same as other modifiers already do]. Differential Revision: https://developer.blender.org/D10873
Diffstat (limited to 'source/blender/gpencil_modifiers')
-rw-r--r--source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
index eca82f4cb90..d6e151fd262 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
@@ -33,6 +33,7 @@
#include "DNA_defaults.h"
#include "DNA_gpencil_modifier_types.h"
#include "DNA_gpencil_types.h"
+#include "DNA_material_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
@@ -275,8 +276,25 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel)
uiItemR(sub, ptr, "crease_threshold", UI_ITEM_R_SLIDER, " ", ICON_NONE);
uiItemPointerR(layout, ptr, "target_layer", &obj_data_ptr, "layers", NULL, ICON_GREASEPENCIL);
- uiItemPointerR(
- layout, ptr, "target_material", &obj_data_ptr, "materials", NULL, ICON_SHADING_TEXTURE);
+
+ /* Material has to be used by grease pencil object already, it was possible to assign materials
+ * without this requirement in earlier versions of blender. */
+ bool material_valid = false;
+ PointerRNA material_ptr = RNA_pointer_get(ptr, "target_material");
+ if (!RNA_pointer_is_null(&material_ptr)) {
+ Material *current_material = material_ptr.data;
+ Object *ob = ob_ptr.data;
+ material_valid = BKE_gpencil_object_material_index_get(ob, current_material) != -1;
+ }
+ uiLayout *row = uiLayoutRow(layout, true);
+ uiLayoutSetRedAlert(row, !material_valid);
+ uiItemPointerR(row,
+ ptr,
+ "target_material",
+ &obj_data_ptr,
+ "materials",
+ NULL,
+ material_valid ? ICON_SHADING_TEXTURE : ICON_ERROR);
uiItemR(layout, ptr, "use_remove_doubles", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "use_edge_overlap", 0, IFACE_("Overlapping Edges As Contour"), ICON_NONE);