Here is my code of the function in questiion:

void DrawScene(LPDIRECT3DDEVICE9 p_dx_Device, LPDIRECT3DVERTEXBUFFER9 p_dx_VertexBuffer, LPDIRECT3DINDEXBUFFER9 p_dx_IndexBuffer)
{
	p_dx_Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,60), 1.0f, 0);
	p_dx_Device->BeginScene();

	p_dx_Device->SetStreamSource(0, p_dx_VertexBuffer, 0, sizeof(OURCUSTOMVERTEX));
	p_dx_Device->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE);
	p_dx_Device->SetIndices(p_dx_IndexBuffer);

	D3DXMATRIX m_Rotation;
	D3DXMatrixRotationZ(&m_Rotation, flt_Angle);
	D3DXMATRIX m_Translation;
	D3DXMatrixTranslation(&m_Translation, 32, -32, 0);

	D3DXMATRIX m_World;
	D3DXMatrixMultiply(&m_World, &m_Translation, &m_Rotation);
	p_dx_Device->SetTransform(D3DTS_WORLD, &m_World);

	p_dx_Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, int_VertCount, 0, int_PrimCount);

	p_dx_Device->EndScene();
	p_dx_Device->Present(NULL, NULL, NULL, NULL);
}

the following line is the error line:

p_dx_Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, int_VertCount, 0, int_PrimCount);

when i build it, no errors occur, however upon running i get:

Unhandled exception at 0x4ff4f522 in testdx.exe: 0xC0000005: Access violation reading location 0x00231ad8.

now i have done a little debugging already. i have found that none of my variables or pointers to variables in my entire program are set at memory location 0x00231ad8, or any where close for that matter. I bring up the memory listing for that area, and there are "?" all over.... the closest variable that the function DrawIndexedPrimitive should use (and that my program includes) is at 0x002197c0, and none of the relevant variables would indicate any entries out of the range of that vector.

my question is more along the lines of "why is it trying to access this memory location if none of my pointers or variables indicate values needed are there? and how do i solve this annoying little error?" i am at wits end.

Any Help would be much appreciated.
Thanks.

The functions you call are probably attempting to access that memory location because of bad arguments you send it. Check the value of pointers such as p_dx_Device to make sure they are valid and the value of the parameters sent to make sure they are correct. for example what is the value of int_VertCount ? Is it a valid value ?

The functions you call are probably attempting to access that memory location because of bad arguments you send it. Check the value of pointers such as p_dx_Device to make sure they are valid and the value of the parameters sent to make sure they are correct. for example what is the value of int_VertCount ? Is it a valid value ?

int_vertCount = 5
int_PrimCount = 3

p_dx_Device is a object created by the DirectX function Direct3DCreate9::CreateDevice and is populated properly as well as passed properly.

the DrawIndexedPrimitive function syntax is:

DrawIndexedPrimitive(
  D3DPRIMITIVETYPE Type,
  INT BaseVertexIndex,
  UINT MinIndex,
  UINT NumVertices,
  UINT StartIndex,
  UINT PrimitiveCount
);

according to the SDK.

Below is the code where the values are stored for the Vertexs and Indices:

int LoadIndicesAndVerts(HWND han_Window, LPDIRECT3DDEVICE9 p_dx_Device, char *s_fName, LPDIRECT3DVERTEXBUFFER9 &p_VertBuf, LPDIRECT3DINDEXBUFFER9 &p_IndBuf)
{
	OCVArray p_verts;
	SArray p_Inds;

	int i_errorRetruned = LoadVerts(s_fName, p_verts, p_Inds, int_VertCount, int_TotalInd);
	int_PrimCount = int_TotalInd/3;

	// create the vertex buffer variable
	LPDIRECT3DVERTEXBUFFER9 p_dx_VertexBuffer;

	// try to initialize the vertexbuffer otherwise pop error
	if (FAILED(p_dx_Device->CreateVertexBuffer(int_VertCount*sizeof(OURCUSTOMVERTEX), 0, D3DFVF_XYZ|D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &p_dx_VertexBuffer, NULL)))
	{
		MessageBox(han_Window, "Error While Creating VertexBuffer.", "FillVertices()", MB_OK);
	}

	// declare pointer for pointer in memory where vertices will be stored for d3d to find them
	// declare pointer for pointer in memory where vertices will be stored for d3d to find them
	VOID* p_Vertices;

	// try to lock the memory location so other progs cannot access while copying vertices to it or pop error
	if(FAILED(p_dx_VertexBuffer->Lock(0, int_VertCount*sizeof(OURCUSTOMVERTEX), (void**)&p_Vertices, 0)))
	{
		MessageBox(han_Window, "Error while trying to lock memory for Verts.", "FillVertices()", MB_OK);
	}
	else
	{
		// copy verts from array to memory and return pointer to location in memory to p_Vertices
		memcpy(p_Vertices, &p_verts, int_VertCount*sizeof(OURCUSTOMVERTEX));
		// unlock allocated memory area
		p_dx_VertexBuffer->Unlock();
	}

	p_VertBuf = p_dx_VertexBuffer;

	// create the index buffer and if it does not work pop an error
	LPDIRECT3DINDEXBUFFER9 p_dx_IndexBuffer;
	if (FAILED(p_dx_Device->CreateIndexBuffer(int_TotalInd*sizeof(short), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &p_dx_IndexBuffer, NULL)))
	{
		MessageBox(han_Window, "Error creating the IndexBuffer.", "FillIndices()", MB_OK);
	}

	// store index buffer in dx managed memory by locking, storing, unlocking for safe copy
	VOID* p_Indices;
	if(FAILED(p_dx_IndexBuffer->Lock(0, int_TotalInd*sizeof(short), (void**)&p_Indices, 0)))
	{
		MessageBox(han_Window, "Error while trying to Lock memory for copy.", "FillIndices()", MB_OK);
	}
	else
	{
		memcpy(p_Indices, &p_Inds, int_TotalInd*sizeof(short));
		p_dx_IndexBuffer->Unlock();
	}

	p_IndBuf = p_dx_IndexBuffer;

	return 0;
}

the LoadVerts function is a function solely for the purpose of extracting the vertex information from my custom file format (which is working properly). The file being loaded is a simple 3 triangle file for testing.... I am befuddled.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.