Game Development Community

Shadow assert in setActiveRenderSurface()

by Tom Spilman · in Torque Game Engine Advanced · 09/08/2006 (8:58 am) · 1 replies

Hey guys. I'm getting the following assert from time to time...

From gfxD3DDevice.cpp @ Line 819
AssertFatal(mCurrentTexture[i] != mCurrentRTData.renderTarget[ renderTargetIndex ], 
            "GFXD3DDevice::setActiveRenderSurface - Cannot have an active render target bound to a texture sampler!");

I'm currently doing some vehicle physics work and i get launched or dropped till no terrain is visible. This sometimes causes this assert to occur. Tracing this back it came from the shadow projector code...

void sgShadowProjector::sgRenderShadowBuffer()
{
	RectI originalview = GFX->getViewport();

	GFX->pushActiveRenderSurfaces();
	GFX->pushActiveZSurface();
	GFX->setActiveRenderSurface(sgShadowLODObject.sgShadowTexture); // ASSERT!
	GFX->setActiveZSurface(sgShadowSharedZBuffer::sgGetZBuffer());

The shadow code puts the sgShadowLODObject.sgShadowTexture into texture stage 2. When there are other things to render eventually that stage gets NULL'd out. But when the scene is clear, stage 2 isn't emptied, and causes this assert.

I hacked a fix by doing this on the two exit points from sgShadowProjector::sgRender()..

GFX->setTexture(0, NULL); // Clear the stages we used.
	GFX->setTexture(1, NULL); // Clear the stages we used.
	GFX->setTexture(2, NULL); // Clear the stages we used.
	GFX->setTexture(3, NULL); // Clear the stages we used.
	GFX->setTextureStageColorOp(4, GFXTOPDisable);
	GFX->setTextureStageColorOp(3, GFXTOPDisable);
	GFX->setTextureStageColorOp(2, GFXTOPDisable);
	GFX->setTextureStageColorOp(1, GFXTOPDisable);
	GFX->setTextureStageMagFilter(0, GFXTextureFilterLinear);
	GFX->setTextureStageMinFilter(0, GFXTextureFilterLinear);
	GFX->setTextureStageColorOp(0, GFXTOPDisable);
	GFX->setZEnable(true);
	GFX->setZWriteEnable(true);
	GFX->setSrcBlend(GFXBlendOne);
	GFX->setDestBlend(GFXBlendZero);
	GFX->setAlphaTestEnable(false);
	GFX->popWorldMatrix();
	GFX->disableShaders();

	PROFILE_END();
}

But i suppose there could be a better way to restore the texture stages.

About the author

Tom is a programmer and co-owner of Sickhead Games, LLC.


#1
09/08/2006 (7:14 pm)
Good catch Tom, I've committed the change to svn.