Fix T49136: full constant Curves with zero Fac input crashes in assert.
authorAlexander Gavrilov <angavrilov@gmail.com>
Mon, 22 Aug 2016 08:11:45 +0000 (11:11 +0300)
committerAlexander Gavrilov <angavrilov@gmail.com>
Mon, 22 Aug 2016 08:11:45 +0000 (11:11 +0300)
The if branches were reordered when the original patch was
committed, which broke the implicit non-NULL guarantee on link.

To prevent re-occurrence, add a couple of unit tests.

intern/cycles/render/nodes.cpp
intern/cycles/test/render_graph_finalize_test.cpp

index 4f54b86fe4a1268ba2daddd2d3fabdf7557e971e..0304d6d95d1aadb76b3410f90df3efbc9c9dbf06 100644 (file)
@@ -4846,12 +4846,8 @@ void CurvesNode::constant_fold(const ConstantFolder& folder, ShaderInput *value_
 {
        ShaderInput *fac_in = input("Fac");
 
-       /* remove no-op node */
-       if(!fac_in->link && fac == 0.0f) {
-               folder.bypass(value_in->link);
-       }
        /* evaluate fully constant node */
-       else if(folder.all_inputs_constant()) {
+       if(folder.all_inputs_constant()) {
                if (curves.size() == 0)
                        return;
 
@@ -4864,6 +4860,11 @@ void CurvesNode::constant_fold(const ConstantFolder& folder, ShaderInput *value_
 
                folder.make_constant(interp(value, result, fac));
        }
+       /* remove no-op node */
+       else if(!fac_in->link && fac == 0.0f) {
+               /* link is not null because otherwise all inputs are constant */
+               folder.bypass(value_in->link);
+       }
 }
 
 void CurvesNode::compile(SVMCompiler& compiler, int type, ShaderInput *value_in, ShaderOutput *value_out)
index 633e517ce9fe1844c5ed915e8fd3abcd4d83be66..60e41be16aa3cdd1d1bb584320ce2a544b680539 100644 (file)
@@ -401,6 +401,26 @@ TEST(render_graph, constant_fold_invert_fac_0)
        graph.finalize(&scene);
 }
 
+/*
+ * Tests:
+ *  - Folding of Invert with zero Fac and constant input.
+ */
+TEST(render_graph, constant_fold_invert_fac_0_const)
+{
+       DEFINE_COMMON_VARIABLES(builder, log);
+
+       EXPECT_ANY_MESSAGE(log);
+       CORRECT_INFO_MESSAGE(log, "Folding Invert::Color to constant (0.2, 0.5, 0.8).");
+
+       builder
+               .add_node(ShaderNodeBuilder<InvertNode>("Invert")
+                         .set("Fac", 0.0f)
+                         .set("Color", make_float3(0.2f, 0.5f, 0.8f)))
+               .output_color("Invert::Color");
+
+       graph.finalize(&scene);
+}
+
 /*
  * Tests:
  *  - Folding of MixRGB Add with all constant inputs (clamp false).
@@ -1344,6 +1364,33 @@ TEST(render_graph, constant_fold_rgb_curves_fac_0)
        graph.finalize(&scene);
 }
 
+
+/*
+ * Tests:
+ *  - Folding of RGB Curves with zero Fac and all constant inputs.
+ */
+TEST(render_graph, constant_fold_rgb_curves_fac_0_const)
+{
+       DEFINE_COMMON_VARIABLES(builder, log);
+
+       EXPECT_ANY_MESSAGE(log);
+       CORRECT_INFO_MESSAGE(log, "Folding Curves::Color to constant (0.3, 0.5, 0.7).");
+
+       array<float3> curve;
+       init_test_curve(curve, make_float3(0.0f, 0.25f, 1.0f), make_float3(1.0f, 0.75f, 0.0f), 257);
+
+       builder
+               .add_node(ShaderNodeBuilder<RGBCurvesNode>("Curves")
+                         .set(&CurvesNode::curves, curve)
+                         .set(&CurvesNode::min_x, 0.1f)
+                         .set(&CurvesNode::max_x, 0.9f)
+                         .set("Fac", 0.0f)
+                         .set("Color", make_float3(0.3f, 0.5f, 0.7f)))
+               .output_color("Curves::Color");
+
+       graph.finalize(&scene);
+}
+
 /*
  * Tests:
  *  - Folding of Vector Curves with all constant inputs.