Sending LPDIRECT3DDEVICE9 to a class func.

Started by
0 comments, last by shakazed 20 years, 2 months ago
Hi! I have a class in my project that takes care of loading and rendering .x files. The problem is that after I pass my LPDIRECT3DDEVICE interface ptr to the first load function it collapses, with that I mean that I can´t use the ptr cuz then I get an error. The func. looks like this.

HRESULT CXModel::LoadXFile(char* p_strPathModelname, char* p_strPathTexturename, LPDIRECT3DDEVICE9 lpD3DDev9)
{
	LPD3DXBUFFER lpD3DXMtrlBuffer;

	if(FAILED(D3DXLoadMeshFromX(p_strPathModelname, D3DXMESH_SYSTEMMEM, lpD3DDev9, NULL,
		&lpD3DXMtrlBuffer, NULL, &lNumMtrls, &lpD3DXMesh)))
	{
		MessageBox(NULL, "Failed to load .x file", "DX_02.exe", MB_OK);
	}

	d3dxMtrl = (D3DXMATERIAL*)lpD3DXMtrlBuffer->GetBufferPointer();
	d3dMaterials = new D3DMATERIAL9[lNumMtrls];
	lpD3DTexture = new LPDIRECT3DTEXTURE9[lNumMtrls];

	for(unsigned long i = 0; i<lNumMtrls; i++)
	{
		d3dMaterials[i] = d3dxMtrl[i].MatD3D;
		d3dMaterials[i].Ambient = d3dMaterials[i].Diffuse;

		if(FAILED(D3DXCreateTextureFromFile(lpD3DDev9, p_strPathTexturename,
			&lpD3DTexture[i])))
		{
			MessageBox(NULL, "Failed to load texture", "DX_02.exe", MB_OK);
		}
		
	}

	lpD3DXMtrlBuffer->Release();
	
	return S_OK;
}
And this is how I call the function, passing my LPDIRECT3DDEVICE ptr.

CXModel cMap;
cMap.RenderXFile(lpD3DDev9);
Oh, the class is in a seperate file. Bad Monkey Productions
Advertisement
What kind of error are you getting? Is there any output to the debug spew? Could the pointer be getting passed in as NULL? Have you tried stepping into this function with the debugger?

neneboricua

This topic is closed to new replies.

Advertisement