diff options
author | Charlie Jolly <charlie> | 2019-11-06 17:19:58 +0300 |
---|---|---|
committer | Charlie Jolly <mistajolly@gmail.com> | 2019-11-06 17:20:00 +0300 |
commit | 3a65ea3b2d62235fdabf9eeeade675e2b1e338aa (patch) | |
tree | ffbfaf07b079242586618b0ecdeb979fb91500f2 /source/blender | |
parent | e71963a37e76bb52524e36816286db28fdbbcf57 (diff) |
Fix: Forward compatibility issue in shader nodes
Raised in https://developer.blender.org/rBe5618725fd1e
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D6102
Diffstat (limited to 'source/blender')
6 files changed, 56 insertions, 20 deletions
diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c index 455da4b3881..b16c814ade9 100644 --- a/source/blender/nodes/intern/node_util.c +++ b/source/blender/nodes/intern/node_util.c @@ -82,7 +82,10 @@ void *node_initexec_curves(bNodeExecContext *UNUSED(context), void node_blend_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen) { const char *name; - RNA_enum_name(rna_enum_ramp_blend_items, node->custom1, &name); + bool enum_label = RNA_enum_name(rna_enum_ramp_blend_items, node->custom1, &name); + if (!enum_label) { + name = "Unknown"; + } BLI_strncpy(label, IFACE_(name), maxlen); } @@ -96,21 +99,30 @@ void node_image_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int ma void node_math_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen) { const char *name; - RNA_enum_name(rna_enum_node_math_items, node->custom1, &name); + bool enum_label = RNA_enum_name(rna_enum_node_math_items, node->custom1, &name); + if (!enum_label) { + name = "Unknown"; + } BLI_strncpy(label, IFACE_(name), maxlen); } void node_vector_math_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen) { const char *name; - RNA_enum_name(rna_enum_node_vec_math_items, node->custom1, &name); + bool enum_label = RNA_enum_name(rna_enum_node_vec_math_items, node->custom1, &name); + if (!enum_label) { + name = "Unknown"; + } BLI_strncpy(label, IFACE_(name), maxlen); } void node_filter_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen) { const char *name; - RNA_enum_name(rna_enum_node_filter_items, node->custom1, &name); + bool enum_label = RNA_enum_name(rna_enum_node_filter_items, node->custom1, &name); + if (!enum_label) { + name = "Unknown"; + } BLI_strncpy(label, IFACE_(name), maxlen); } diff --git a/source/blender/nodes/shader/nodes/node_shader_mapping.c b/source/blender/nodes/shader/nodes/node_shader_mapping.c index d607fcdc7a1..7905cabab9f 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mapping.c +++ b/source/blender/nodes/shader/nodes/node_shader_mapping.c @@ -50,7 +50,12 @@ static int gpu_shader_mapping(GPUMaterial *mat, [NODE_MAPPING_TYPE_NORMAL] = "mapping_normal", }; - return GPU_stack_link(mat, node, names[node->custom1], in, out); + if (node->custom1 < ARRAY_SIZE(names) && names[node->custom1]) { + return GPU_stack_link(mat, node, names[node->custom1], in, out); + } + else { + return 0; + } } static void node_shader_update_mapping(bNodeTree *UNUSED(ntree), bNode *node) diff --git a/source/blender/nodes/shader/nodes/node_shader_math.c b/source/blender/nodes/shader/nodes/node_shader_math.c index aaedc4aa1b7..db623c5599b 100644 --- a/source/blender/nodes/shader/nodes/node_shader_math.c +++ b/source/blender/nodes/shader/nodes/node_shader_math.c @@ -68,14 +68,19 @@ static int gpu_shader_math(GPUMaterial *mat, [NODE_MATH_ARCTAN2] = "math_arctan2", }; - GPU_stack_link(mat, node, names[node->custom1], in, out); + if (node->custom1 < ARRAY_SIZE(names) && names[node->custom1]) { + int ret = GPU_stack_link(mat, node, names[node->custom1], in, out); - if (node->custom2 & SHD_MATH_CLAMP) { - float min[3] = {0.0f, 0.0f, 0.0f}; - float max[3] = {1.0f, 1.0f, 1.0f}; - GPU_link(mat, "clamp_value", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link); + if (ret && node->custom2 & SHD_MATH_CLAMP) { + float min[3] = {0.0f, 0.0f, 0.0f}; + float max[3] = {1.0f, 1.0f, 1.0f}; + GPU_link(mat, "clamp_value", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link); + } + return ret; + } + else { + return 0; } - return 1; } static void node_shader_update_math(bNodeTree *UNUSED(ntree), bNode *node) diff --git a/source/blender/nodes/shader/nodes/node_shader_mixRgb.c b/source/blender/nodes/shader/nodes/node_shader_mixRgb.c index ae2184d8237..74936fedbd2 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mixRgb.c +++ b/source/blender/nodes/shader/nodes/node_shader_mixRgb.c @@ -88,13 +88,18 @@ static int gpu_shader_mix_rgb(GPUMaterial *mat, "mix_linear", }; - int ret = GPU_stack_link(mat, node, names[node->custom1], in, out); - if (ret && node->custom2 & SHD_MIXRGB_CLAMP) { - float min[3] = {0.0f, 0.0f, 0.0f}; - float max[3] = {1.0f, 1.0f, 1.0f}; - GPU_link(mat, "clamp_color", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link); + if (node->custom1 < ARRAY_SIZE(names) && names[node->custom1]) { + int ret = GPU_stack_link(mat, node, names[node->custom1], in, out); + if (ret && node->custom2 & SHD_MIXRGB_CLAMP) { + float min[3] = {0.0f, 0.0f, 0.0f}; + float max[3] = {1.0f, 1.0f, 1.0f}; + GPU_link(mat, "clamp_color", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link); + } + return ret; + } + else { + return 0; } - return ret; } void register_node_type_sh_mix_rgb(void) diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.c b/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.c index c0f9a033476..ec4fedec27c 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_white_noise.c @@ -50,7 +50,12 @@ static int gpu_shader_tex_white_noise(GPUMaterial *mat, "node_white_noise_4d", }; - return GPU_stack_link(mat, node, names[node->custom1], in, out); + if (node->custom1 < ARRAY_SIZE(names) && names[node->custom1]) { + return GPU_stack_link(mat, node, names[node->custom1], in, out); + } + else { + return 0; + } } static void node_shader_update_tex_white_noise(bNodeTree *UNUSED(ntree), bNode *node) diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_math.c b/source/blender/nodes/shader/nodes/node_shader_vector_math.c index 03de83655b5..ba53cfd1799 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vector_math.c +++ b/source/blender/nodes/shader/nodes/node_shader_vector_math.c @@ -65,8 +65,12 @@ static int gpu_shader_vector_math(GPUMaterial *mat, [NODE_VECTOR_MATH_MAXIMUM] = "vector_math_maximum", }; - GPU_stack_link(mat, node, names[node->custom1], in, out); - return true; + if (node->custom1 < ARRAY_SIZE(names) && names[node->custom1]) { + return GPU_stack_link(mat, node, names[node->custom1], in, out); + } + else { + return 0; + } } static void node_shader_update_vector_math(bNodeTree *UNUSED(ntree), bNode *node) |