Problem using LPD3DXEFFECT

Started by
3 comments, last by Programmer101 16 years, 10 months ago
I have a class that handles post processing effects in my program. I can access and initialize all of the variables in the class including the LPD3DXEFFECT. However, if I load the effect using D3DXCreateEffectFromFile the program will crash as it is exiting. It is very strange because everything works fine until I exit the program. The error even comes up when I don't release COMs. Here is the error I get:
Quote:Unhandled exception at 0x00401e70 in armageddon.exe: 0xC0000005: Access violation reading location 0x00000008.
and the directx debug gives me no information. What is the problem? Thanks
Advertisement
The first thought that springs to mind is a memory leak somewhere but the DX Debug process should tell you that when you exit.

I don't recall seeing that problem with my old Effect Class. And just tested it with DXDebug switched on. It might be more basic than your own but here's what I have in it. Feel free to take a gander in case you spot something you overlooked.

CDXEffect::CDXEffect(LPDIRECT3DDEVICE9 pD3DDevice,LPCTSTR szFileName){	m_pD3DDevice = pD3DDevice;	m_pD3DEffect = NULL;	m_pD3DDefines = NULL;	m_pD3DInclude = NULL;	m_pD3DPool = NULL;	m_pD3DCompileErrors = NULL;	m_dwShaderFlags = NULL;	m_szFileName = szFileName;	m_bCreated = false;}CDXEffect::~CDXEffect(){	m_pD3DDefines = NULL;	m_pD3DInclude = NULL;	m_szFileName = NULL;	m_szTechnique = NULL;	if (m_bCreated)	{		SAFE_RELEASE(m_pD3DCompileErrors);		SAFE_RELEASE(m_pD3DPool);		SAFE_RELEASE(m_pD3DEffect);	}}bool CDXEffect::CreateFromFile(void){		m_dwShaderFlags = D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION;	HRESULT hr = D3DXCreateEffectFromFile(m_pD3DDevice,m_szFileName,							 m_pD3DDefines,m_pD3DInclude,							 m_dwShaderFlags,m_pD3DPool,							 &m_pD3DEffect,&m_pD3DCompileErrors);	if (hr == D3D_OK) 	{		m_bCreated = true;		return true;	}	if (hr == D3DERR_INVALIDCALL)	{		MessageBox(NULL,"Invalid Call","Create Effect from File",MB_OK);		return false;	}	if (hr == D3DXERR_INVALIDDATA)	{		MessageBox(NULL,"Invalid Data","Create Effect from File",MB_OK);		return false;	}	if (hr == E_OUTOFMEMORY) 	{		MessageBox(NULL,"Out of Memory","Create Effect from File",MB_OK);		return false;	}		if (!m_pD3DEffect) 	{		LPCTSTR buff = (LPCTSTR)m_pD3DCompileErrors->GetBufferPointer();		MessageBox(NULL,buff,"Compiler Errors",MB_OK);		return false;	}	return true;}void CDXEffect::UseTechnique(void){	HRESULT hr = m_pD3DEffect->SetTechnique(m_pD3DEffect->GetTechniqueByName(m_szTechnique));	if (hr == D3D_OK)	{	}	if (hr == D3DERR_INVALIDCALL)	{		MessageBox(NULL,"Invalid Call","UseTechnique",MB_OK);	}}void CDXEffect::SetTechnique(LPCTSTR szTechnique){	m_szTechnique = szTechnique;}UINT CDXEffect::Begin(void){	UINT passes;	HRESULT hr = m_pD3DEffect->Begin(&passes,D3DXFX_DONOTSAVESTATE);	if (hr == D3D_OK) return passes;	if (hr == D3DERR_INVALIDCALL)	{		MessageBox(NULL,"Invalid Call","Begin Effect",MB_OK);		return 0;	}	if (hr == D3DXERR_INVALIDDATA)	{		MessageBox(NULL,"Invalid Data","Begin Effect",MB_OK);		return 0;	}	return 0;}void CDXEffect::BeginPass(UINT pass){	m_pD3DEffect->BeginPass(pass);}void CDXEffect::EndPass(void){	m_pD3DEffect->EndPass();}void CDXEffect::End(void){	m_pD3DEffect->End();}


Good luck. Hope you find the culprit soon.
Now that I took it out of the class I do get a direct-x debug error. In fact I get about 2000 pages of:

Quote:Direct3D9: (ERROR) : [0] : Address 010FD4CB
Direct3D9: (ERROR) : [1] : Address 010FD59B
Direct3D9: (ERROR) : [2] : Address 010FD440
Direct3D9: (ERROR) : [3] : Address 0111EA65
Direct3D9: (ERROR) : [4] : Address 0111F161
Direct3D9: (ERROR) : [5] : Address 0112D3E4
Direct3D9: (ERROR) : [6] : Address 0112DD06
Direct3D9: (ERROR) : [7] : Address 011EB111
Direct3D9: (ERROR) : [8] : Address 011F4D7F
Direct3D9: (ERROR) : [9] : Address 0121F4CE
Direct3D9: (ERROR) : [10] : Address 011E61A9
Direct3D9: (ERROR) : [11] : Address 004AE985
Direct3D9: (ERROR) : [12] : Address 004023EE
Direct3D9: (ERROR) : [13] : Address 00000000
Direct3D9: (ERROR) : [14] : Address 00000000
Direct3D9: (ERROR) : [15] : Address 00000000

[lol]


I took the effect and device out of a class and tried to see if it were the class protection that was the problem. It wasn't. So now I'm fairly sure the problem is the way I am loading it. Again, the program works perfectly until it exits. This is the code, maybe an error could be spotted:

BOOL TogglePost(const char *Filename){	HRESULT hr;	//Effect handle	D3DXHANDLE hTech;	if(Filename==NULL)		post = false;	else {		post = true;		DWORD m_dwShaderFlags = 0;				if(FAILED(D3DXCreateEffectFromFile(g_pD3DDevice, Filename, NULL, NULL, m_dwShaderFlags, NULL, &g_pEffect, NULL)))			return FALSE;		//Select technique and store result		if(FAILED(g_pEffect->FindNextValidTechnique(NULL,&hTech)))			return FALSE;		if(FAILED(effectt=g_pEffect->ValidateTechnique(hTech)))			return FALSE;		if(FAILED(effectt=g_pEffect->SetTechnique(hTech)))			return FALSE;	}	return TRUE;}


Thanks!

Quote:
//Select technique and store result
if(FAILED(g_pEffect->FindNextValidTechnique(NULL,&hTech)))
return FALSE;
if(FAILED(effectt=g_pEffect->ValidateTechnique(hTech)))
return FALSE;
if(FAILED(effectt=g_pEffect->SetTechnique(hTech)))
return FALSE;


I've never used these commands myself so will have to try it to see what happens in my case.
.. Okay, I added ValidateTechnique to my code and worked a treat. My effect file has multiple techniques in that have to be used specifically so can't use the FindNext option.

Also, what is effectt? it seems to be a variable of some manner but I am not seeing it being initialised, set or used anywhere else in that code. Ah I am guessing it is HRESULT variable.


Another thought I have is maybe try removing the use of the effect file and see if the program falls over using the fixed program functionality. I usually do this if I get a memory error and can't find where the owner of the problem is.
Yeah, I found part of the problem. I had to change m_dwShaderFlags to D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION.

Now it works fine using the release version of the directx sdk. However, I still get an error in debug mode =/. And I think it still wont work in its own class.

This topic is closed to new replies.

Advertisement