-
Notifications
You must be signed in to change notification settings - Fork 944
Closed
Description
I've gotten to chapter seven, when my program has stopped at 20% of image generation with exit code 3221225725.
Above number is 0xc00000fd in hex, which is stack overflow error in windows.
Dev C++'s debugger shows me quite an interesting trace:
Here's the code I've written:
vec3 rius(mt19937_64 rng) {
vec3 p;
do {
p = 2.0*vec3(unif(rng), unif(rng), unif(rng)) - vec3(1,1,1);
} while (p.squaredLength() >= 1.0);
return p;
}
vec3 color(const ray & r, hitable *world, mt19937_64 rng)
{
HitRecord rec;
if (world->hit(r, 0.0, FLT_MAX, rec))
{
vec3 target = rec.p + rec.normal + rius(rng);
return 0.5*color(ray(rec.p, target-rec.p), world, rng);
}
else
{
vec3 unitDirection = unit(r.direction());
float t = 0.5 * (unitDirection.y() + 1.0);
return (1.0-t)*vec3(1.0, 1.0, 1.0) + t*vec3(0.2, 0.5, 1.0);
}
}
rng is just me passing a random number generator engine not to have scope issues.
From the backtrace provided, it would seem that the ray perhaps has hit the sphere on the inside?
The trace is very long and consists solely of the color() function, which would suggest me that it's due to function recursion.
Any help is appreciated, as I can't find any errors with the code above.