Browse Source

[shgraph] Fix changing texture param not updating graph if it was null

Clément Espeute 8 months ago
parent
commit
938ad93714
1 changed files with 14 additions and 4 deletions
  1. 14 4
      hide/view/shadereditor/ShaderEditor.hx

+ 14 - 4
hide/view/shadereditor/ShaderEditor.hx

@@ -441,14 +441,16 @@ class ShaderEditor extends hide.view.FileView implements GraphInterface.IGraphEd
 		execMoveParameterTo(parameter, parameterPrev, !up);
 	}
 
-	function updateParam(id : Int) {
+	function updateParam(id : Int) : Bool {
 		meshPreviewScene.setCurrent(); // needed for texture changes
 
 		var param = shaderGraph.getParameter(id);
 		var init = compiledShader.inits.find((i) -> i.variable.name == param.name);
 		if (init != null) {
 			setParamValue(meshPreviewShader, init.variable, param.defaultValue);
+			return true;
 		}
+		return false;
 	}
 
 	var parametersUpdate : Map<Int, (Dynamic) -> Void> = [];
@@ -666,7 +668,12 @@ class ShaderEditor extends hide.view.FileView implements GraphInterface.IGraphEd
 							var v = !isUndo ? curr : prev;
 							shaderGraph.setParameterDefaultValue(parameter.id, v);
 							parametersUpdate[parameter.id](v);
-							updateParam(parameter.id);
+
+							if (!updateParam(parameter.id)) {
+								// If the graph was initialised without the variable,
+								// we need to recompile it
+								requestRecompile();
+							}
 						}
 						exec(false);
 						this.undo.change(Custom(exec));
@@ -674,8 +681,11 @@ class ShaderEditor extends hide.view.FileView implements GraphInterface.IGraphEd
 					}
 					if (!shaderGraph.setParameterDefaultValue(parameter.id, currentValue))
 						return;
-					//setBoxesParam(parameter.id);
-					updateParam(parameter.id);
+					if (!updateParam(parameter.id)) {
+						// If the graph was initialised without the variable,
+						// we need to recompile it
+						requestRecompile();
+					}
 				}
 				typeName = "Texture";