Fix #108591: Handle null material adding paint slot #108592
|
@ -6637,9 +6637,12 @@ static void default_paint_slot_color_get(int layer_type, Material *ma, float col
|
|||
case LAYER_ROUGHNESS:
|
||||
case LAYER_METALLIC: {
|
||||
bNodeTree *ntree = nullptr;
|
||||
ma->nodetree->ensure_topology_cache();
|
||||
const blender::Span<bNode *> nodes = ma->nodetree->nodes_by_type("ShaderNodeBsdfPrincipled");
|
||||
bNode *in_node = nodes.is_empty() ? nullptr : nodes.first();
|
||||
bNode *in_node = nullptr;
|
||||
if (ma && ma->nodetree) {
|
||||
ma->nodetree->ensure_topology_cache();
|
||||
const blender::Span<bNode *> nodes = ma->nodetree->nodes_by_type("ShaderNodeBsdfPrincipled");
|
||||
in_node = nodes.is_empty() ? nullptr : nodes.first();
|
||||
ChengduLittleA marked this conversation as resolved
Outdated
|
||||
}
|
||||
if (!in_node) {
|
||||
/* An existing material or Principled BSDF node could not be found.
|
||||
* Copy default color values from a default Principled BSDF instead. */
|
||||
|
@ -6870,7 +6873,8 @@ static int texture_paint_add_texture_paint_slot_invoke(bContext *C,
|
|||
get_default_texture_layer_name_for_object(ob, type, (char *)&imagename, sizeof(imagename));
|
||||
RNA_string_set(op->ptr, "name", imagename);
|
||||
|
||||
/* Set default color. Copy the color from nodes, so it matches the existing material. */
|
||||
/* Set default color. Copy the color from nodes, so it matches the existing material.
|
||||
* Material could be null so we should have a default color. */
|
||||
float color[4];
|
||||
default_paint_slot_color_get(type, ma, color);
|
||||
RNA_float_set_array(op->ptr, "color", color);
|
||||
|
|
Loading…
Reference in New Issue
Am I missing something?
nodes.is_empty() ? nullptr : nodes.first();
doesn't seem to do anything