# LPDIRECT3DDEVICE9 Device failure

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

## Recommended Posts

Hello, I'm encountering an unusual problem. I'm using the August 2007 update and my game loads initilizes the device like this:
    D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = FALSE;
d3dpp.hDeviceWindow = hwnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferWidth = SCREEN_WIDTH;
d3dpp.BackBufferHeight = SCREEN_HEIGHT;

D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &gD3dDevice);

if (FAILED(hr)) {
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &gD3dDevice);
if (CheckFailed(hr, "Failed to create Direct3d device"))
return false;
}//if


The resolution is 1280 x 960 and I've had no problem on my computer and the computers at home that I've tested this game on. However, when I test it on other computers (they all have the latest version of DirectX), I'm getting the error. The computer's I tested have a native widescreen resolution if it helps. Interestingly, when I run another game that I made (this one isn't fullscreen), it works perfectly on these computers. The code for that is:
        D3DPRESENT_PARAMETERS presParams;

ZeroMemory(&presParams,sizeof(presParams));
presParams.Windowed = true;
presParams.BackBufferFormat=D3DFMT_UNKNOWN;
presParams.BackBufferCount=1;

if (FAILED(hr))
{
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presParams, &gD3dDevice);

if (FAILED(hr))
{
MessageBox(NULL, "Failed to create Direct3d device", "Error", NULL);
return false;
}
}



##### Share on other sites
What error are you getting? What D3D function is failing? What's the return value? Are you sure the device supports the resolution you're passing in? What does IDirect3D9::CheckDeviceFormat tell you?

##### Share on other sites
I am getting a message box which says "Failed to create Direct3d device", which I programmed to be displayed when the CreateDevice function fails. I'm not sure what the return value is but FAILED(hr) is returning true. I did not set any formats.

##### Share on other sites
Just FYI - You can use (char*)DXGetErrorDescription(hr) to display in your message box. But, in all likelihood, all you'll get is "Invalid Parameter" in this case.

EDIT: Another FYI - you probably want to try D3DCREATE_HARDWARE_VERTEXPROCESSING in your first create call, rather than calling for D3DCREATE_SOFTWARE_VERTEXPROCESSING twice. [smile]

##### Share on other sites
Quote:
 Original post by beatdown_masterI am getting a message box which says "Failed to create Direct3d device", which I programmed to be displayed when the CreateDevice function fails. I'm not sure what the return value is but FAILED(hr) is returning true.
All that tells you is that the return value is one of 2 billion possible results. You should store the return value as a HRESULT variable (As you are, in the hr variable), and then check if it's a filed code. If it is, then you can log it (As a 8-digit hex number), or use DXGetErrorDescription or DXGetErrorString to convert it to a human readable error code.

Quote:
 Original post by beatdown_masterI did not set any formats.
Yes you did:
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;

That tells D3D yo use that format as the backbuffer, but the device might not support that mode. It might not also support the resolution, but that's another matter. You should always use IDirect3D9::CheckDeviceFormat to make sure the device supports that format. Try adding the following before your first CreateDevice() call:
hr = gD3dObject->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, D3DFMT_X8R8G8B8);if(FAILED(hr)){   // Format not supported}

I think that's right anyway, I'm not entirely sure.

Also, you really shouldn't be calling CreateDevice() twice. If it fails the first time, it'll fail the second. If it was a typo as Buckeye suggested, then you should be checking the device caps to see if hardware vertex processing is possible (If the D3DDEVCAPS_HWTRANSFORMANDLIGHT cap bit is set in the DevCaps member of D3DCAPS9).

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 27
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634098
• Total Posts
3015525
×