Sign in to follow this  
Garra

Shader Problem

Recommended Posts

EDIT: Problem solved

I keep getting a unhandled exception error when calling D3DX10CreateEffectFromFile.

[code]
Unhandled exception at 0x69056d41 in TestApp.exe: 0xC0000005: Access violation writing location 0xccccccdc.
[/code]

Basically I'm building a class to load models, but started having this issue. I have a MeshLoader class that has all my shader variables like below. Also I replace my shader file with a basic one that I knew worked just to see what would happen and it still has the same issue.

[code]
private:
ID3DX10Mesh* m_dxMesh;

UINT m_numVertices;
UINT m_numTriangles;

ID3D10Effect* m_Effect;
ID3D10InputLayout* m_Layout;
ID3D10EffectTechnique* m_Technique;
[/code]

The problem is in the InitializeShader function. This is from a function in the MeshLoader class called ImportMesh. ImportMesh has a lot of code in it, but here is the shader specific parts.

[code]
if (!(InitializeShader(device, L"basicEffect.fx")))
{
MessageBox(NULL, L"Failed to initialize mesh shader", L"ERROR", MB_ICONERROR);
return false;
}

//creates the vertexDesc
D3D10_INPUT_ELEMENT_DESC vertexDesc[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
};

UINT numElements = (sizeof(vertexDesc) / sizeof(vertexDesc[0]));
[/code]

Lastly is the InitializeShader function, the unhandled exception occurs when D3DX10CreateEffectFromFile is called.
[code]
bool MeshLoader::InitializeShader(ID3D10Device* device, std::wstring file)
{
HRESULT result;
ID3D10Blob* errorMessage;

//Initialize pointer to 0
errorMessage = 0;

result = D3DX10CreateEffectFromFile(file.c_str(),
0,
0,
"fx_4_0",
D3D10_SHADER_ENABLE_STRICTNESS,
0,
device,
0,
0,
&m_Effect,
&errorMessage,
0);

if (FAILED(result))
return false;

m_Technique = m_Effect->GetTechniqueByName("render");

if (!m_Technique)
return false;

return true;
}
[/code]

Share this post


Link to post
Share on other sites
Hidden
well i thought i had this fixed but apparently not. I'm still getting the below message when i run the program. It breaks when D3DX10CreateEffectFromFile is called. I simplified the program tremendously to weed out problems and I'm basically down to a mesh class that can load a shader.

Error Message:
[code]
Unhandled exception at 0x69056d41 in AssimpTestApp.exe: 0xC0000005: Access violation writing location 0xcccccccc.
[/code]


here is my simplified initializeshader function inside the MeshLoader class. All it is currently doing is calling D3DX10CreateEffectFromFile. this is also where the problem is. The only thing even close to a clue I'm getting out of this is when clicking on m_pBasicEffect while debugging it sometimes says CXX0017: Error: symbol "" not found. I've loaded shaders quite a few times and this is the first time I've had problems, so I don't see how it could be a project properties setting. I have also tried moving the shader code into the main cpp file and all works well. It just has the problem inside of my MeshLoader class. All shader related variables such as m_pBasicEffect are initialized to 0 in the class constructor.

[code]
bool MeshLoader::InitializeShader(ID3D10Device* device, std::wstring filename)
{
if ( FAILED( D3DX10CreateEffectFromFile( filename.c_str(),
NULL,
NULL,
"fx_4_0",
D3D10_SHADER_ENABLE_STRICTNESS,
0,
device,
NULL,
NULL,
&m_pBasicEffect,
NULL,
NULL ) ) ) return false;

return true;
}
[/code]

class header:
[code]
#ifndef _MESHLOADER_
#define _MESHLOADER_

#include "d3dUtil.h"
#include <string>

class MeshLoader
{
public:
MeshLoader();
~MeshLoader();

bool ImportMesh(ID3D10Device* device, std::string filename);
D3DXVECTOR2 AIVec3ToD3DX2(const aiVector3D &source);
D3DXVECTOR3 AIVec3ToD3DX(const aiVector3D &source);

bool InitializeShader(ID3D10Device* device, std::wstring filename);
void Shutdown();
void Render(ID3D10Device* device);

private:

ID3D10Effect* m_pBasicEffect;
ID3D10InputLayout* m_layout;
ID3D10EffectTechnique* m_pTechnique;

const struct aiScene* m_Scene;
ID3DX10Mesh* m_dxMesh;

UINT m_numVertices;
UINT m_numTriangles;

ID3D10ShaderResourceView* m_shaderResourceView;
};


#endif

[/code]

so yeah.. i'm confused, any ideas would be appreciated.

Share this post


Link to post
Guest
This topic is now closed to further replies.
Sign in to follow this