• Advertisement
Sign in to follow this  

Possible pointer problem

This topic is 2307 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a AI class and ran into the following error that i think is being caused by a pointer problem. Any help would be appreciated.

Error:

Unhandled exception at 0x69626d41 in FinalGame.exe: 0xC0000005: Access violation writing location 0xcccccd04.


Basically I have a AI class called CEnemy and a shader class called CColorShader. Inside my CEnemy class I add..

CColorShader* m_pColorShader; //Shader object


Then in my main game file I call the CEnemy class initialize function like so.
m_Enemy.Initialize(m_d3dDevice, m_MainWnd, D3DXVECTOR3(0, 0, 0));

Here's the initialization function
bool CEnemy::Initialize(ID3D10Device* device, HWND hwnd, D3DXVECTOR3 pos)
{
//Initialize the shader
if (!(m_pColorShader->Initialize(device, hwnd)))
{
MessageBox(hwnd, L"Failed to initialize enemy shader", L"ERROR", MB_ICONERROR);
return false;
}

//Initialize the enemy objects
InitializeObject(device, hwnd, pos);

return true;
}


Shader Initialization function:
bool CColorShader::Initialize(ID3D10Device* device, HWND hwnd)
{
bool result;

//Initialize the vertex and pixel shaders.
result = InitializeShader(device, hwnd, L"color.fx");

if (!result)
return false;

return true;
}


and here is were the problem occurs, it seems to me that its a pointer issue with the device. The error comes up when D3DX10CreateEffectFromFile is called.
bool CColorShader::InitializeShader(ID3D10Device* device, HWND hwnd, WCHAR* filename)
{
HRESULT result;
ID3D10Blob* errorMessage;
unsigned int numElements;
D3D10_PASS_DESC passDesc;

errorMessage = 0;

result = D3DX10CreateEffectFromFile(filename, NULL, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0,
/*breaks on this line*/ device, NULL, NULL, &m_effect, &errorMessage, NULL);

if (FAILED(result))
{
if (errorMessage)
{
OutputShaderErrorMessage(errorMessage, hwnd, filename);
}
else
{
MessageBox(hwnd, filename, L"Missing Shader File", MB_OK);
}

return false;
}

m_technique = m_effect->GetTechniqueByName("ColorTechnique");

if (!m_technique)
return false;

// Create the vertex input layout description.
// This setup needs to match the VertexType stucture in the ModelClass and in the shader.
polygonLayout[0].SemanticName = "POSITION";
polygonLayout[0].SemanticIndex = 0;
polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
polygonLayout[0].InputSlot = 0;
polygonLayout[0].AlignedByteOffset = 0;
polygonLayout[0].InputSlotClass = D3D10_INPUT_PER_VERTEX_DATA;
polygonLayout[0].InstanceDataStepRate = 0;

polygonLayout[1].SemanticName = "COLOR";
polygonLayout[1].SemanticIndex = 0;
polygonLayout[1].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
polygonLayout[1].InputSlot = 0;
polygonLayout[1].AlignedByteOffset = D3D10_APPEND_ALIGNED_ELEMENT;
polygonLayout[1].InputSlotClass = D3D10_INPUT_PER_VERTEX_DATA;
polygonLayout[1].InstanceDataStepRate = 0;

// Get a count of the elements in the layout.
numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]);

m_technique->GetPassByIndex(0)->GetDesc(&passDesc);

// Create the vertex input layout.
result = device->CreateInputLayout(polygonLayout, numElements, passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &m_layout);
if(FAILED(result))
{
return false;
}

m_worldMatrixPtr = m_effect->GetVariableByName("worldMatrix")->AsMatrix();
m_viewMatrixPtr = m_effect->GetVariableByName("viewMatrix")->AsMatrix();
m_projectionMatrixPtr = m_effect->GetVariableByName("projectionMatrix")->AsMatrix();

return true;
}


Screenshot:
errorbfr.png

Share this post


Link to post
Share on other sites
Advertisement
Looks like you're using a pointer that hasn't been set to point to anything.

You need to first create a CColorShader object someplace and then put the address of that object into your m_pColorShader pointer. There are a number of techniques for this but each has its restrictions and drawbacks. The first question I would ask is, why do you need a pointer to the CColorShader in this particular location?

Share this post


Link to post
Share on other sites
thanks I fixed the issue, i just needed to know what the cause was since it was confusing me a bit.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement