D3D Error: "Failed to initialize primary swapchain"

Recommended Posts

Alright, so I'm new to DX - so what? :-P Anyway, I'm just trying my hand at DX. So far, I've succeeded at creating a DX window... when it's windowed =\. It doesn't work when it's fullscreen. I've looked everywhere I can look to help see what the problem is (MSDN, google, gamedev forum search, etc.) but I can't seem to find a solution. So here's what I got so far... My application fails at the call to IDirect3D9::CreateDevice(). The return value is D3DERR_INVALIDCALL which according to msdn means that "The method call is invalid. For example, a method's parameter may have an invalid value." The last time this happened to me, I altered the D3DPRESENT_PARAMETERS structure that I sent to the function. However, I'm not even sure why it was wrong then either. To fix the problem, I just changed the multisampling member as you'll see below. Anyway, here's the code for my filling in of the members of the D3DPRESENT_PARAMETERS structure.
void TestGame::GetD3DParams( D3DPRESENT_PARAMETERS ¶ms )
{
// Fill in the paramaters
params.BackBufferHeight = 640;
params.BackBufferWidth = 480;
if(windowed) params.BackBufferFormat=D3DDisplayMode.Format;
else params.BackBufferFormat = D3DFMT_X8R8G8B8;
params.hDeviceWindow = myWnd.hWnd;
params.Windowed = windowed;
params.BackBufferCount = 1;

// This is the portion that was giving me problems the first time
/*if( FAILED(pD3D9->CheckDeviceMultiSampleType(
params.BackBufferFormat,
windowed, D3DMULTISAMPLE_2_SAMPLES, NULL)))
{
params.MultiSampleType=D3DMULTISAMPLE_NONE;
}
else
{
params.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
}*/

// I changed it to the next line
params.MultiSampleType = D3DMULTISAMPLE_NONE;
params.EnableAutoDepthStencil = TRUE;
params.AutoDepthStencilFormat = D3DFMT_D16;
params.FullScreen_RefreshRateInHz = 0;
if(windowed) params.PresentationInterval = 0;
else params.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
params.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
}

So yeah, after changing what I commented out above, I no longer have the problem in windowed mode, but I still have the problem in fullscreen mode. The debug spew says: Direct3D9: (ERROR) :The specified mode is unsupported. CreateDevice/Reset Fails Direct3D9: (ERROR) :Unable to set the new mode. CreateDevice/Reset Fails Direct3D9: (ERROR) :Failed to initialize primary swapchain Direct3D9: (ERROR) :Failed to initialize Framework Device. CreateDevice Failed. I can't imagine what could be the problem. Can anyone help me? - Mak

Share on other sites
Kibble    504
try getting rid of D3DPRESENTFLAG_LOCKABLE_BACKBUFFER on the last line of your function.

Share on other sites
Alvarny    124
Are you sure your card supports X8R8G8B8?

Share on other sites
The problem persists. Same debug spew too. First I tried comenting it out and then I just set it to zero. Neither solution worked. Out of curiosity - if it did work, don't I need to be able to lock the buffer in order to alter it and render stuff on it?

- Mak

Share on other sites
Quote:
 Original post by AlvarnyAre you sure your card supports X8R8G8B8?

Actually, I'm not. I also tried R5G6B5 but that didn't work either. Anything else more common I can try?

- Mak

Share on other sites
Kibble    504
Just for shits and giggles, try setting AutoDepthStencil to FALSE. Also, are you sure D3DDisplayMode.Format is initialized? set a breakpoint on that line in the debugger and check to make sure it is what you think it is.

Share on other sites
Quote:
 Original post by KibbleJust for shits and giggles, try setting AutoDepthStencil to FALSE. Also, are you sure D3DDisplayMode.Format is initialized? set a breakpoint on that line in the debugger and check to make sure it is what you think it is.

Hm. Not working. The .Format is what I expect it to be and it's not what is being assigned when it's fullscreen(which is where the problem occurs). *Sigh*, hehe. Thanks very much for your help though!

_mak_lives

Edit: Fixed typos

Share on other sites
Oh boy... such a silly mistake. I just realized, I mixed up the dimensions: I put height = 640 and width = 480. =P. Thanks kibble and alvarny for your help.

- Mak