You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the final code from book 3 to render a scene lacking explicitly-declared light sources (eg. any scene from book 1), it is natural to camera::render() passing an emptyhittable_list as the lights argument. However, this causes a segmentation fault, because the current implementation of hittable_list::random() assumes the list to contain at least one member:
classhittable_list : publichittable {
public:
...
vec3 random(const point3& origin) constoverride {
auto int_size = int(objects.size());
return objects[random_int(0, int_size-1)]->random(origin); // if int_size is 0, this index is negative
}
}
Proposed fix
There are several fixes possible here. Perhaps the simplest fix is to make camera::render() take a hittable_list of lights, and then only construct a mixture PDF in ray_color if the list of lights is non-empty.
This method would obviously not fix crashes in the event that one of the elements of the lights hittable_list is itself an empty hittable_list (more generally that other empty hittable_lists appear further down the scene tree of lights), but this is admittedly a strange contingency to guard against.
The text was updated successfully, but these errors were encountered:
Summary
When using the final code from book 3 to render a scene lacking explicitly-declared light sources (eg. any scene from book 1), it is natural to
camera::render()
passing an emptyhittable_list
as thelights
argument. However, this causes a segmentation fault, because the current implementation ofhittable_list::random()
assumes the list to contain at least one member:Proposed fix
There are several fixes possible here. Perhaps the simplest fix is to make
camera::render()
take ahittable_list
of lights, and then only construct a mixture PDF inray_color
if the list of lights is non-empty.This method would obviously not fix crashes in the event that one of the elements of the lights
hittable_list
is itself an emptyhittable_list
(more generally that other emptyhittable_list
s appear further down the scene tree of lights), but this is admittedly a strange contingency to guard against.The text was updated successfully, but these errors were encountered: