Game Development Community

After enabling projectile shadows...

by Faraz Ahmed · in · 01/25/2006 (10:11 am) · 2 replies

I have a requirement for my projectile to cast a shadow. The projectile happens to be a ball that moves slowly (relative to gun fire) close to the ground.

What I have done so far is to blatantly replicate the ShapeBase::renderShadow(F32 dist, F32 fogAmount) function in sgShadow.cc and create a new Projectile::renderShadow method which I'm calling from the Projectile::renderObject function. The projectile which is dynamically created via the script is casting shadows correctly now but here is the weirdness....

I'm getting random crashes only in the Release build. This is happening in the renderShadow function at this point ..
void Projectile::renderShadow(F32 dist, F32 fogAmount)
{
	
	if(sgSceneObjectData.sgDisableDynamicShadows)
		return;
	if(Shadow::getGlobalShadowDetailLevel()<mDataBlock->noShadowLevel)
		return;
	if(mProjectileShape->getShape()->subShapeFirstTranslucentObject.empty() ||
		mProjectileShape->getShape()->subShapeFirstTranslucentObject[0] == 0)
		return;
	

	Vector<LightInfo *> lights;
	LightManager *lm = gClientSceneGraph->getLightManager();
	lm->sgGetValidLights(lights);
	
	// ambient must be last!
	
	for(U32 i=0; i<lights.size(); i++)
	{
		// ........................... CRASHES HERE ....................................
		LightInfo *light = lights[i];
		// ........................... CRASHES HERE ....................................
		
		if(light->mType != LightInfo::Ambient)
			continue;
		
		U32 il = lights.size() - 1;
		if(i == il)
			continue;
		
		// swap...
		LightInfo *last = lights[il];
		lights[il] = light;
		lights[i] = last;
		
		break;
	}
        .
        .
        .

Can anyone shed some light as to why this may be happening intermittently and only in release mode. Quite painful to debug =(

p.s. I would also like to apologize if this seems like a cross-post but its an extension of something i posted in the general discussions section and i figured that this might be the right forum for it. Thnx.

#1
01/25/2006 (11:37 pm)
Hey Faraz,

This should be posted in the TLK Private forums, as you're posting code and we'll probably post more.

Out of curiousity why are you trying to create projectile shadows? That sounds like a lot of overhead, for something that won't be too noticable.

Something that concerns me is the debugger showed you the line that crashed in release mode, usually VC dumps you out to a page of machine code. Are you sure you're not in a debug version, or that the problem doesn't also occur in the debug version?

Off the top of my head I can say the projectile class doesn't receive lighting so the light array is going to be empty, but that shouldn't crash the code.

Btw: I posted code for adding lighting to projectiles in the TLK Private formus - you might want to check that out.

-John
#2
01/26/2006 (2:05 am)
Hi John,

I'm evaluating torque for building a multiplayer (2 players) sports game simulator. The game features a close up view of the ball near the ground which I'm creating as a projectile. Since there is going to be only one projectile at any given time, I wasn't afraid of the overhead (... or should I be *gulp*).

I isolated the crash point via painfully inserting console printfs all over the function while running in release mode. Strangely, the projectile shadows are being created fine and no crashes occur in the debug build.

I'll hop over to the TLK private forums to check out your code. You just saved me a lot of time... thanks much!

Faraz