# Some failures with DEBUG DirectX9

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

## Recommended Posts

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;
CopyMemory(pData,faces,sizeof(BACKGROUNDVERTEX2D)*4); //FAILURE
pVertexBuffer2D->Unlock();
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.

##### Share on other sites
With the debug runtime, whenever you hit an error, DX will output an error line into the Output window in your compiler (if you're using VS, this might be called something else in other compilers). That line should have a full explaination of why the function failed...

Hope this helps.

##### Share on other sites
I don't see that 'error line', only I have a windows that says:

Excepción no controlada en 0x7c911230 en DES.exe: Punto de interrupción del usuario.

With the DEBUG compiler options ('stop', 'continue', etc.).

The solution to problem 2 is changing the D3DLOCK_DISCARD in 'Lock' for 0.

pVertexBuffer2D->Lock(0,0,(VOID**) &pData,0);pIndexBuffer2D->Lock(0,0,(VOID**) &pData,0);

But I don't know why it fails in the line:

gfx.pd3dDevice->SetLight(0,&lights[0]);

##### Share on other sites
I would guess that the first one is because you have not completely filled out the D3DLIGHT9 structure.

##### Share on other sites
Quote:
 Original post by Dark SchneiderThe solution to problem 2 is changing the D3DLOCK_DISCARD in 'Lock' for 0.
Yes. That's because D3DLOCK_DISCARD and D3DLOCK_NOOVERWRITE are only valid for dynamic VBs, and you're creating a static VB. To use a dynamic VB, specify D3DUSAGE_DYNAMIC when creating it.

Quote:
 Original post by Dark SchneiderBut I don't know why it fails in the line:*** Source Snippet Removed ***
As jamesw said, it's probably from not filling out the whole structure. Can we see your exact code? Or is that your exact code?
Another point is that the direction should probably be normalised. Although I doubt even the debug runtimes would catch that.

What does "Punto de interrupción del usuario" translate into English as? The debug runtimes in this case are just breaking whenever a D3D function returns failure, you should still get some sort of output in the debug window. Do you get any output to do with D3D there? Is your debug output level set to maximum in the DirectX control panel?

##### Share on other sites
Yes, that is the solution, with a simple ZeroMemory(&lights[0],sizeof(D3DLIGHT9)); it works well.

I think these problems is because I am using the DEBUG DX recently and in RETAIL we don't have this error messages.

Thanks.

##### Share on other sites
Quote:
 Original post by Dark SchneiderI think these problems is because I am using the DEBUG DX recently and in RETAIL we don't have this error messages.
You should always use the debug runtimes for development. If your app doesn't work with the debug runtimes, but does with the retail runtimes, it means something is wrong that the driver or runtime is letting you get away with (Usually for performance reasons it doesn't check a lot of things). That means that on other drivers it's entirely possible that it'll not work or crash your app entirely.

##### Share on other sites
Quote:
Original post by Evil Steve
Quote:
 Original post by Dark SchneiderI think these problems is because I am using the DEBUG DX recently and in RETAIL we don't have this error messages.
You should always use the debug runtimes for development. If your app doesn't work with the debug runtimes, but does with the retail runtimes, it means something is wrong that the driver or runtime is letting you get away with (Usually for performance reasons it doesn't check a lot of things). That means that on other drivers it's entirely possible that it'll not work or crash your app entirely.

I agree completely. The previous statement that code "runs well" on retail directx, but not on debug is incorrect. That code "happens to run" on retail, but if you can't validate the correctness against debug directx, then it's not really right, and you're just asking for trouble later.

• 10
• 17
• 9
• 14
• 41