Jump to content
  • Advertisement
Sign in to follow this  
caseyd

Failing to create Dx9 device for Fullscreen mode

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I seem to be having a problem when I try to create a Directx9 device for fullscreen. It works fine in windowed mode. Here is how I am setting up the D3DPRESENT_PARAMETERS structure:
D3DPRESENT_PARAMETERS d3dpp;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferHeight = 640;
d3dpp.BackBufferWidth = 480;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.Flags = 0;
d3dpp.hDeviceWindow = hwnd;
d3dpp.MultiSampleQuality = 0;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.PresentationInterval = 0;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	
	
#if defined (FULLSCREEN)
	d3dpp.Windowed = FALSE;
	d3dpp.FullScreen_RefreshRateInHz = 60;
#else
	d3dpp.Windowed = TRUE;
	d3dpp.FullScreen_RefreshRateInHz = 0;
#endif

Creating the device:
HRESULT hr = g_d3d9->CreateDevice (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,  hwnd, 									D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_d3d9Device);

The Output from Debug:
Quote:
Direct3D9: (INFO) :Direct3D9 Debug Runtime selected. Direct3D9: (INFO) :======================= Hal SWVP device selected Direct3D9: (INFO) :HalDevice Driver style 9 Direct3D9: :Subclassing window 000e066e Direct3D9: :StartExclusiveMode 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. Direct3D9: :DoneExclusiveMode Direct3D9: :INACTIVE: 00000a70: Restoring original mode (1440x900x22x60) at adapter index 0 Direct3D9: :Unsubclassing window 000e066e D3D9 Helper: IDirect3D9::CreateDevice failed: D3DERR_INVALIDCALL First-chance exception at 0x00411279 in small.exe: 0xC0000005: Access violation reading location 0x00000000. Unhandled exception at 0x00411279 in small.exe: 0xC0000005: Access violation reading location 0x00000000. The program '[2672] small.exe: Native' has exited with code 0 (0x0).
I am new to DirectX, so I am not sure how to interpret some of this. I googled around for a few hours yesterday and today, and know that this is a common problem when an incorrect value is specified as part of the D3DPRESENT_PARAMETERS structure. I checked the settings I am using with the DXCapsViewer utility, and they all appear to be valid modes. I also tried setting the Device Type to D3DDEVTYPE_REF, but that didn't help either. I have also read, that when using Fullscreen, that the HWND being past in must be a top level window, so I have also specified that. Actually, here's the Window creation code:
HWND hwnd = CreateWindowEx (WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST, "STATIC", "Small", 
								WS_POPUP | WS_VISIBLE, 
								0, 0,
								640, 480,
								0, 0, hInstance, 0);

This whole thing is a very bare bones application, as I am working on producing a sub 4kb executable. So I am also not linking to any common libs other than kernel32.lib and user32.lib, as well as d3d9.lib, just in case that has something to do with it. Thanks, caseyd

Share this post


Link to post
Share on other sites
Advertisement
You need to find out whether the mode you want to go into in full screen is acceptable.

Try something like:

D3DDISPLAYMODE DisplayMode;
m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &DisplayMode);
hr = m_pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,DisplayMode.Format,D3DUSAGE_RENDERTARGET,D3DRTYPE_SURFACE,D3DFMT_A8R8G8B8);
if( FAILED(hr) ) {
MessageBox(NULL,"Device format is unaccepatble for full screen mode","Sorry",MB_OK);
return E_FAIL;
}
//set fullscreen parameters
m_PresentParameters.BackBufferFormat = D3DFMT_A8R8G8B8;
m_PresentParameters.Windowed = FALSE;
m_PresentParameters.BackBufferWidth = DisplayMode.Width;
m_PresentParameters.BackBufferHeight = DisplayMode.Height;
m_PresentParameters.hDeviceWindow = m_hwnd; //window handle

Share this post


Link to post
Share on other sites
I think I spotted a classic little 'gotcha' in your code [wink]

Quote:
d3dpp.BackBufferHeight = 640;
d3dpp.BackBufferWidth = 480;


I think you might want to swap those two values around... [smile]

hth
Jack

Share this post


Link to post
Share on other sites
The depth-buffer format looks suspect to me. A lot of cards don't support a depth buffer that isn't the same bit-depth as the backbuffer. You should check support with IDirect3D9::CheckDepthStencilMatch. From my engine code:

D3DFORMAT PGraphics::GetDepthBufferFormat(D3DFORMAT fmtBackBuffer)
{
D3DFORMAT fmtBuffers[] =
{
D3DFMT_D24S8,
D3DFMT_D32,
D3DFMT_D24X8,
D3DFMT_D24FS8,
D3DFMT_D24X4S4,
D3DFMT_D15S1,
D3DFMT_D16,
D3DFMT_D32F_LOCKABLE,
D3DFMT_D16_LOCKABLE
};
const char* szBuffers[] =
{
"D3DFMT_D24S8\n",
"D3DFMT_D32\n",
"D3DFMT_D24X8\n",
"D3DFMT_D24FS8\n",
"D3DFMT_D24X4S4\n",
"D3DFMT_D15S1\n",
"D3DFMT_D16\n",
"D3DFMT_D32F_LOCKABLE\n",
"D3DFMT_D16_LOCKABLE\n"
};
D3DFORMAT fmtAdapter;

// Get adapter format
if(m_thePresentParams.Windowed)
{
D3DDISPLAYMODE mode;
if(FAILED(m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode)))
return D3DFMT_UNKNOWN;
fmtAdapter = mode.Format;
}
else
fmtAdapter = fmtBackBuffer;

// Check formats
ELog::Get().SystemLog("RENDER : Choosing depth-stencil format... ");
for(DWORD i=0; i<sizeof(fmtBuffers)/sizeof(D3DFORMAT); ++i)
{
HRESULT hResult = m_pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, m_eDevType,
fmtAdapter, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, fmtBuffers);
if(FAILED(hResult))
continue;
if(SUCCEEDED(m_pD3D->CheckDepthStencilMatch(D3DADAPTER_DEFAULT, m_eDevType,
fmtAdapter, fmtBackBuffer, fmtBuffers)))
{
ELog::Get().SystemLog(szBuffers);
return fmtBuffers;
}
}
ELog::Get().SystemLog("Failed\n");
return D3DFMT_UNKNOWN;
}

That code goes through each of the listed formats in turn, and checks first if the format is available (The card supports that format at all), and then if the format is usable in the specified display mode, with the specified backbuffer format.

Share this post


Link to post
Share on other sites
Quote:

I think I spotted a classic little 'gotcha' in your code

Quote:
d3dpp.BackBufferHeight = 640;
d3dpp.BackBufferWidth = 480;



I think you might want to swap those two values around...

hth
Jack


Yep, that was it.

Thanks!
Casey

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!