Jump to content

View more

Image of the Day

I've done more tweaks to my color palette selector. #gamedev #screenshotsaturday #madewithunity https://t.co/aJXrC4ruRg
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Trouble creating swap chain

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Rizzmond   Members   


Posted 29 August 2012 - 02:28 PM

I recently started learning D3D11 and have run into trouble initializing it. I'm getting a E_INVALIDARG when calling the CreateSwapChain function. Relevant code is as follows:

D3D_DRIVER_TYPE md3dDriverType = D3D_DRIVER_TYPE_HARDWARE; // driver type
IDXGISwapChain * swap_chain;
ID3D11Device* md3dDevice;
  UINT D3d_Device_Flags = D3d_Device_Flags | D3D11_CREATE_DEVICE_DEBUG; //device flags
  D3D_FEATURE_LEVEL featureLevel;
  ID3D11DeviceContext* md3dImmediateContext;
  HRESULT hr = D3D11CreateDevice(
   0,				 // default adapter
   0,				 // no software device
   0, 0,			  // default feature level array

  DXGI_SWAP_CHAIN_DESC swap_chain_desc;
  swap_chain_desc.BufferDesc.Width  = client_width; // a value of 0 uses current window values
  swap_chain_desc.BufferDesc.Height = client_height; // a value of 0 uses current window values
  swap_chain_desc.BufferDesc.RefreshRate.Numerator = 60;
  swap_chain_desc.BufferDesc.RefreshRate.Denominator = 1;
  swap_chain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // display format
  swap_chain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; //method the raster uses to create an image on a surface.
  swap_chain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; //how an image is stretched to fit a given monitor's resolution
  swap_chain_desc.SampleDesc.Count = 4; //4 sub pixels per sample
  swap_chain_desc.SampleDesc.Quality = m4xMsaaQuality; //msaa quality level

  swap_chain_desc.BufferUsage  = DXGI_USAGE_RENDER_TARGET_OUTPUT;
  swap_chain_desc.BufferCount  = 1;
  swap_chain_desc.OutputWindow = window_handle;
  swap_chain_desc.Windowed	 = true;
  swap_chain_desc.SwapEffect   = DXGI_SWAP_EFFECT_DISCARD;
  swap_chain_desc.Flags		= 0;
  // retrieve IDXGIFactory instance used to create device
  IDXGIDevice* dxgiDevice = 0;
  check_for_fail(md3dDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice));
  IDXGIAdapter* dxgiAdapter = 0;
  check_for_fail(dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&dxgiAdapter));
  IDXGIFactory* dxgiFactory = 0;
  check_for_fail(dxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&dxgiFactory));
  check_for_fail(dxgiFactory->CreateSwapChain(md3dDevice, &swap_chain_desc, &swap_chain));

I can't figure out why the parameters I passed are incorrect. In the remarks for the CreateDeviceAndSwapChain functionit says "If you set the pAdapter parameter to a non-NULL value and the DriverType parameter to the D3D_DRIVER_TYPE_HARDWARE value, D3D11CreateDeviceAndSwapChain returns an HRESULT of E_INVALIDARG." However, i'm using a null value for the pAdapter parameter (besides the fact i'm not even using that function). Otherwise, I haven't had any luck finding related information. Thanks in advance for help.

#2 Brian Klamik   Members   


Posted 07 September 2012 - 10:34 AM

I suspect the issue is the flags you pass.

Initialize D3d_Device_Flags to 0 first. The following line is very suspect, because D3d_Device_Flags is declared and read from within the same statement:
UINT D3d_Device_Flags = D3d_Device_Flags | D3D11_CREATE_DEVICE_DEBUG; //device flags

Then, make sure the computer has the SDK installed on it or remove the _DEBUG flag, as CreateDevice will fail with that flag if the SDK is not installed on the computer you run the program on.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.