Ray Tracing in Two Months

A couple months ago I took a stab at Peter Shirley's excellent Ray Tracing in One Weekend project. I got most of the way through it, but ended up with a bug I just couldn't figure out about half-way through it and put it down. I picked it back up again in February and figured out pretty quickly what I did wrong. It turns out, when you have an array of pointers and you decided to initialize the array elements like this:


list[0] = new ...
list[0] = new ...
list[0] = new ...

when you try to reference element 1 or greater, it'll give you a segfault. The more you know! Switching these to:


list[0] = new ...
list[1] = new ...
list[2] = new ...

did the trick. Silver lining? I learned an eensy bit of GDB and Valgrind. Anyways, here's an image showing what it can do:

Rendering of balls of various sizes and materials

I realized in hindsight that I did version 1.55 of the project from back in 2018, whereas the current version. 3.2, released in 2020 and has some additional niceties such as 'auto' and shared pointers; that will explain why my code looks kind of different than the reference code available on Github. Can't say I'm going to redo the whole shtick with modern C++ features, but maybe I'll take a crack at parallelizing it or moving everything over to CUDA.