Page MenuHome

Cycles: Divide by zero with sky texture
Closed, ResolvedPublic

Description

System Information
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: GeForce GTX 1080 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 457.30

Blender Version
Broken: version: 2.92.0 Alpha, branch: master, commit date: 2020-11-29 08:04, hash: rB13c820d87b62
Worked: -

Short description of error
Using a Sky Texture node for the world background results in a divide by zero in background_cdf (light.cpp), because cdf_total is zero.

Exact steps for others to reproduce the error

  1. Start Blender with a debugger attached. Set a breakpoint on the line float cdf_total_inv = 1.0f / cdf_total; with the condition set to cdf_total == 0.0f.
  2. Set the render engine to Cycles.
  3. In the shader editor for the world, add a Sky Texture node and connect it to the Background node.
  4. Set viewport shading to Rendered.

or

  1. Start Blender with a debugger attached. Set a breakpoint on the line float cdf_total_inv = 1.0f / cdf_total; with the condition set to cdf_total == 0.0f.
  2. Open attached file.
  3. Set viewport shading to Rendered.

Event Timeline

Robert Guetzkow (rjg) changed the task status from Needs Triage to Confirmed.Nov 29 2020, 2:37 PM
Robert Guetzkow (rjg) triaged this task as High priority.
Robert Guetzkow (rjg) created this task.

@Brecht Van Lommel (brecht) I'm setting this to high priority since this causes undefined behavior and could lead to a crash.

Brecht Van Lommel (brecht) lowered the priority of this task from High to Normal.EditedNov 29 2020, 5:25 PM

Float division by zero is not undefined behavior, it's well defined that the result is inf in this case. If it causes a crashes or other actual bug it might be high priority, but it's not clear to me from the report.

The division by zero is harmless in this case, but the code can be tweaked a bit for clarity by moving it inside the if (cdf_total > 0.0f) test.

@Brecht Van Lommel (brecht) My bad, seems like the version of UBSan I'm using is being overly cautious as theoretically some compiler might not implement Annex F. GCC and CLANG have the expected IEEE-754 behavior.

See discussion in:
https://bugs.llvm.org/show_bug.cgi?id=19535
https://stackoverflow.com/a/51487703

@Brecht Van Lommel (brecht) Does it make sense to add the check in this case then? Technically, it could cause undefined behavior for compilers that don't implement Annex F / IEEE-754, not sure if that is actually the case for any compilers that are used today.