Game Development Community

Divide By Zero Error

by Jay Barnson · in Torque Game Engine · 01/19/2006 (10:23 pm) · 2 replies

Not sure what I'm doing to cause this, but in debug mode I'm getting a divide by zero error in sgShadow.cc at around line 165:

lightDir = getPosition() - light->mPos;
F32 len = lightDir.len();
lightDir /= len;

I've got some situation occuring where light->mPos is exactly equal to the ShapeBase's position --- probably because a lit explosion is originating at exactly the position of the unmoving object? Anyway, I'm just having it abort casting a shadow in this case for now.

About the author

Jay has been a mainstream and indie game developer for a... uh, long time. His professional start came in 1994 developing titles for the then-unknown and upcoming Sony Playstation. He runs Rampant Games and blogs at Tales of the Rampant Coyote.


#1
01/20/2006 (12:15 pm)
Ouch, good catch. :)

Here is what I added:

lightDir = getPosition() - light->mPos;
				F32 len = lightDir.len();
				[b]if(len == 0.0f)
					continue;[/b]
				lightDir /= len;

-John
#2
01/20/2006 (3:18 pm)
Identical to my fix. :)

Thanks John!