Skip to content

printf statement optimized out #267

@brechtvl

Description

@brechtvl

Another bug found by Michel Anders, if you have these two shaders:

shader test_a(output color C = 0)
{
    C[1] = 1; // does not print when removing this line
    if(C[1] != 0.123456)
        printf("%f\n", C);
}
shader test_b(color C = 0)
{
    Ci = C * diffuse(N);
}

and connect them like this:

./testshade --layer layer_a test_a --layer layer_b test_b --connect layer_a C layer_b C

Then it will not print anything when removing the indicated line, but you would expect it to print in both cases. I guess it's because it fails to do constant folding for that line, that it succeeds in printing.

If you use a float instead of a color it never prints:

shader test_a(output float C = 0)
{
    C = 1;
    if(C != 0.123456)
        printf("%f\n", C);
}
shader test_b(float C = 0.0)
{
    Ci = C * diffuse(N);
}

I might look into a fix later, but don't have time anymore this week for it, so if anyone else feels like fixing go ahead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions