From 0b19f1f4a0b1722c212a098715c35cad6b015215 Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Wed, 13 Mar 2024 05:22:43 +0100 Subject: [PATCH] Fix #119030: Only access Location node input when available Our `node_shader_utils.py` module needs to be updated to account for API changes made during the 4.0 release cycle [1]. Here we need to guard against accessing the "Location" node input if not dealing with the appropriate type of Mapping node. [1] e4ad58114b9d56fe838396a97fe09aff32c79c6a Pull Request: https://projects.blender.org/blender/blender/pulls/119354 --- .../modules/bpy_extras/node_shader_utils.py | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/modules/bpy_extras/node_shader_utils.py b/scripts/modules/bpy_extras/node_shader_utils.py index 0b17212b8ca..ce7646575d5 100644 --- a/scripts/modules/bpy_extras/node_shader_utils.py +++ b/scripts/modules/bpy_extras/node_shader_utils.py @@ -36,6 +36,22 @@ def values_clamp(val, minv, maxv): else: return max(minv, min(maxv, val)) +# TODO: Consider moving node_input_value_set/node_input_value_get into a common utility module if +# more usage merits doing so. If that is done, abstract out the validity check and make it usable +# for node outputs as well. See PR #119354 for details. +def node_input_value_set(node, input, value): + if node is None or input not in node.inputs: + return + + node.inputs[input].default_value = value + + +def node_input_value_get(node, input, default_value=None): + if node is None or input not in node.inputs: + return default_value + + return node.inputs[input].default_value + class ShaderWrapper(): """ @@ -798,13 +814,11 @@ class ShaderImageTextureWrapper(): node_mapping = property(node_mapping_get) def translation_get(self): - if self.node_mapping is None: - return Vector((0.0, 0.0, 0.0)) - return self.node_mapping.inputs["Location"].default_value + return node_input_value_get(self.node_mapping, "Location", Vector((0.0, 0.0, 0.0))) @_set_check def translation_set(self, translation): - self.node_mapping.inputs["Location"].default_value = translation + node_input_value_set(self.node_mapping, "Location", translation) translation = property(translation_get, translation_set)