Dev Notes: Debugging Techniques for Ray Tracer Project


There are different ways to debug your ray tracer according to the problems. Here we list several possible problems you may have in development.

To accelerate your debugging procedure, the command line UI is recommended, which has all features required for debugging, although some of them may be difficult to enable (like those must be enabled through the -j option).

Segfault

This is a (very) common problem for any C/C++ program. The easiest way to locate the problem is running your program with gdb. The following shows the command you can use.

$ gdb bin/ray
(gdb) run input.ray tmp.png
# ...  RUNNING
# ...  Segfault Captured
(gdb) bt
# ...  Backtrace is shown

Now you can locate where the problem is.

Note: cmake -DCMAKE_BUILD_TYPE=Debug is required to enable the debugging symbols, otherwise bt only shows the memory address rather than the line number of your source file.

Suspicious Shading Result

It would be very expensive to render the whole scene in order to fix one pixel. The recommended procedure is

  1. Locate the pixel
  1. Hack CommandLineUI.cpp
  1. Add print/std::cout everywhere you are not sure it is correct.