I sometimes use the DEBUG version of DirectX, it is usefull to search fails that in RETAIL you don't notice, but I have 2 failures that I don't know why:
1) With DEBUG and 'Break on D3D Error' options, and this code:
D3DLIGHT9 lights[2];
lights[0].Type=D3DLIGHT_DIRECTIONAL;
lights[0].Diffuse.r=0.5f;
//.....(lights data init)
lights[0].Direction.x=-1;
lights[0].Direction.y=-1;
lights[0].Direction.z=0;
gfx.pd3dDevice->SetLight(0,&lights[0]); //FAILURE
gfx.pd3dDevice->LightEnable(0,true);
I have a failure in the line marked, without 'Break on D3D Error' option it runs well.
2) With DEBUG, I have this code to create a BackGround object:
struct BACKGROUNDVERTEX2D{
D3DXVECTOR3 position;
float rhw;
float tu,tv;
};
bool CBackground::Initialize(CGFX *P_pGFX)
{
if(P_pGFX==NULL) return false;
pGFX=P_pGFX;
data[0].x=0;
data[0].y=0;
data[1].x=1;
data[1].y=1;
data[2].x=0;
data[2].y=0;
VertexFVF=D3DFVF_XYZRHW|D3DFVF_TEX1|D3DFVF_TEXCOORDSIZE2(0);
pGFX->pd3dDevice->CreateVertexBuffer(sizeof(BACKGROUNDVERTEX2D)*4,D3DUSAGE_WRITEONLY,vertexFVF,pGFX->HWDConfig.d3dPool,&pVertexBuffer2D,NULL);
pGFX->pd3dDevice->CreateIndexBuffer(sizeof(unsigned short)*6,D3DUSAGE_WRITEONLY,D3DFMT_INDEX16,pGFX->HWDConfig.d3dPool,&pIndexBuffer2D,NULL);
//se rellena para que llene la pantalla
float faces[]={
0.0f,0.0f,pGFX->fFarPlane,1.0f,0.0f,0.0f,
0.0f,(float) pGFX->HWDConfig.dwHeight,pGFX->fFarPlane,1.0f,0.0f,1.0f,
(float) pGFX->HWDConfig.dwWidth,0.0f,pGFX->fFarPlane,1.0f,1.0f,0.0f,
(float) pGFX->HWDConfig.dwWidth,(float) pGFX->HWDConfig.dwHeight,pGFX->fFarPlane,1.0f,1.0f,1.0f,
};
//los índices, son siempre fijos
unsigned short dwIndices[]={0,2,1,1,2,3};
VOID *pData;
pVertexBuffer2D->Lock(0,0,(VOID**) &pData,D3DLOCK_DISCARD);
CopyMemory(pData,faces,sizeof(BACKGROUNDVERTEX2D)*4); //FAILURE
pVertexBuffer2D->Unlock();
pIndexBuffer2D->Lock(0,0,(VOID**) &pData,D3DLOCK_DISCARD);
CopyMemory(pData,dwIndices,sizeof(DWORD)*6); //FAILURE
pIndexBuffer2D->Unlock();
return true;
}
As summary, CGFX is the class that have all the graphics data (as Direct3D device, etc.), and the function creates 4 vertices at screen corners, and their indices, so I don't know why it fails in the CopyMemory function.
With RETAIL version it works well.