Fix T49136: full constant Curves with zero Fac input crashes in assert.
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.
This commit is contained in:
parent
28cf9cfd15
commit
eb2ee7212e
Notes:
blender-bot
2023-02-14 08:10:06 +01:00
Referenced by issue #49148, Blender Crash With B select on Skeleton Sketching Referenced by issue #49136, Blender closing when f12 for render is pressed
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue