Sign in to follow this  
treeway

OpenGL CGFX and DirectX

Recommended Posts

Hi Im STILL having problems with CGFX and DirectX. My OpenGL implementation is working but when I compile for DirectX I get Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. when I try to validate the Techniques:
bool CGFX_Effect::load(LPCSTR fileName)
{
	assert(fileName);

	FileName = fileName;

	CGprofile vertexProfile;
	CGprofile pixelProfile;

#ifdef _CGE_OPENGL
	vertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
	pixelProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);

	cgGLSetOptimalOptions(vertexProfile);
	cgGLSetOptimalOptions(pixelProfile);

	cgGLEnableProfile(vertexProfile);
	cgGLEnableProfile(pixelProfile);

	
	cgGLRegisterStates(gCGcontext);
	cgErrorCallback();

	cgGLSetManageTextureParameters(gCGcontext,CG_TRUE);

#else
	
	cgD3D9SetDevice(Renderer->D3DDevice);

	vertexProfile = cgD3D9GetLatestVertexProfile();
	pixelProfile = cgD3D9GetLatestPixelProfile();

	cgD3D9EnableDebugTracing(CG_TRUE);
	cgD3D9RegisterStates(gCGcontext);
	cgD3D9SetManageTextureParameters( gCGcontext, CG_TRUE );
	cgErrorCallback();				
#endif

	mCGeffect = cgCreateEffectFromFile(gCGcontext,fileName,NULL);
	cgErrorCallback();

// This Passes
	if(!mCGeffect || !cgIsEffect(mCGeffect))
	{
		return false;
	}
	
//It crashes in this call
	if(! parseTechniques())
	{
		return false;
	}

	parseParameters();

	return true;
}
inline 
bool CGFX_Effect::parseTechniques()
{

	clearTechniques();

	UINT index = 0;
	char buffer[255];

	static CGtechnique curTechnique;
	curTechnique = cgGetFirstTechnique(mCGeffect);
	CGpass currentPass;

	while(curTechnique)
	{
		CGbool isValid = CG_TRUE;
		isValid = cgValidateTechnique(curTechnique); // THIS IS WHERE IT CRASHES

		if( isValid == CG_TRUE)
		{
			Technique* newTechnique = new Technique();
			validTechniques.push_back(newTechnique);
			newTechnique->handle = curTechnique;
			newTechnique->name = cgGetTechniqueName(curTechnique);
			newTechnique->numPasses = 0;
			newTechnique->index = index;
			
			currentPass = cgGetFirstPass(curTechnique);

			while(currentPass)
			{
				++newTechnique->numPasses;
				currentPass = cgGetNextPass(currentPass);
			}
			
			newTechnique->passArray = new PassParameter[newTechnique->numPasses];

			currentPass = cgGetFirstPass(curTechnique);

			int passIndex = 0;
			while(currentPass)
			{
				newTechnique->passArray[passIndex].name = cgGetPassName(currentPass);
				newTechnique->passArray[passIndex].handle = currentPass;

				sprintf(buffer,"Got A Pass %s",newTechnique->passArray[passIndex].name);
				OutputDebugStr(buffer);

				++ passIndex;
				currentPass = cgGetNextPass(currentPass);
			}			
		}

		curTechnique = cgGetNextTechnique(curTechnique);
		++ index;
	}

	if(validTechniques.size() == 0)
	{
		sprintf(buffer,"Effect: Failed to validate for this hardware. \n Reverting this material to STL");
		OutputDebugStr(buffer);
		return false;
	}else
	{
		currentTechnique = validTechniques[0];
	}

	return true;

}

I have been looking for solutions and according to This Page: "When you pass a parameter that is 64 KB or larger to a function that does not use the __cdecl modifier, the compiler generates incorrect code. When the function that is called tries to return control to the calling function, the compiler triggers the error that is mentioned in the "Symptoms" section. The compiler generates a 16-bit immediate return (RET) that has an operand that is limited to 64 KB. If the parameters that are passed to the function are larger than 64 KB, the stack becomes corrupted when the function returns." In my case this would be the curTechnique parameter - but when I check its size, it's only 4bytes
	int i = sizeof(curTechnique); // i = 4


I tryed the solution offered on the page above where I changed Project Properties >> C/C++ >> Code Generation >> Basic Runtime Checks - To "Stack Frames (/RTCs)" but this hasn't changed anything. I've had this problem for nearly a week now and it's realy slowing me down. I've looked in the Cg documentation and searched the net but cant find a solution anywhere. I cant even find an example of using CgFX with DirectX anywhere. Can anyone help?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this