Jump to content
  • Advertisement
Sign in to follow this  

Direct X 11: Creating the device issue

This topic is 2086 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

I'm trying to jump into Direct X 11 and I'm having some issues creating a device when the adapter is specified


I currently have this custom struct to hold the information of each adapter that could exist. I also have a vector to hold them all in

//Struct to hold adapter information
struct DisplayAdapter
	IDXGIAdapter* adapter;
	DXGI_MODE_DESC* resolutions;
	DXGI_ADAPTER_DESC description;
	UINT numberOfResolutions;

//Vector of all the devices
std::vector<DisplayAdapter> availableDisplayAdapters;

I use this method to find all of the available adapters, which then fills my adapter vector

bool SystemX11::findDisplayAdapters()
        //Clean out the vector of adapters and set the current adapter to 0
	currentAdapter = 0;

	HRESULT result;

        //Create the factory
	IDXGIFactory *factory = NULL;
	result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**) (&factory));

		std::cout<<"Failed to create the factory"<<std::endl;
		return false;
        //Create all the items needs to store and find the display adapters
	DisplayAdapter tempAdapter;
	IDXGIOutput *adapterOutput;
	ZeroMemory(&tempAdapter, sizeof(DisplayAdapter));
	ZeroMemory(&adapterOutput, sizeof(IDXGIOutput));
        //Find all the display adapters
	for(UINT i = 0; factory->EnumAdapters(i, &tempAdapter.adapter) != DXGI_ERROR_NOT_FOUND; ++i)
		//Get the description
		//Get the display modes
		tempAdapter.adapter->EnumOutputs(0, &adapterOutput);
		adapterOutput->GetDisplayModeList(supportedDisplayFormat, 0, &tempAdapter.numberOfResolutions, NULL);
		tempAdapter.resolutions = new DXGI_MODE_DESC[tempAdapter.numberOfResolutions];
		adapterOutput->GetDisplayModeList(supportedDisplayFormat, 0, &tempAdapter.numberOfResolutions, tempAdapter.resolutions);

		//[Debug Stuff]
		std::wcout<<"Display Adapter: "<<tempAdapter.description.Description<<std::endl;
		for(int i = 0; i < tempAdapter.numberOfResolutions; i++)
			if(tempAdapter.resolutions[i].Scaling == 0)
				std::cout<<tempAdapter.resolutions[i].Width<<" x "<<tempAdapter.resolutions[i].Height<<" "<<tempAdapter.resolutions[i].RefreshRate.Numerator/tempAdapter.resolutions[i].RefreshRate.Denominator<<"hz"<<std::endl;
                //Put the new adapter in the vector of available adapters

	//Clean up of stuff

        //CLean up the factor
	if(factory != NULL)
		factory ->Release();
        //Clean up the temp adapter
	if(tempAdapter.adapter != NULL)

        ///Clean the temp resolutions
	if(tempAdapter.resolutions != NULL)
		delete [] tempAdapter.resolutions;

        //Clear the adapter output
	if(adapterOutput != NULL)

	return true;

Here is the clean up adapter method above just in case

bool SystemX11::cleanDisplayAdapters()
        //If there is nothing to clean backout
		return false;

        //For every device do clean up
	for(std::vector<DisplayAdapter>::iterator i = availableDisplayAdapters.begin(); i != availableDisplayAdapters.end(); i++)
		(*i).numberOfResolutions = NULL;
		ZeroMemory(&(*i).description, sizeof(DXGI_ADAPTER_DESC));
		delete [] (*i).resolutions;
        //Clear the vector

	return true;

Now my issue is when I acutally try to create the device, for some reason it fails to create when I use my first adapter in my vector. This is the only adatper I have. Also for some reason if I use NULL in the first parameter the device creates just fine.


Here is my create device code

bool SystemX11::createDirectDevice(int adapterToUse)
        //Make sure we are creating on the right device, adapterToUse is 0 in this case. The first slot in the vector
	std::wcout<<"Creating device from: "<<availableDisplayAdapters[adapterToUse].description.Description<<std::endl;

        //Attempt to create the device
	hr = D3D11CreateDevice(availableDisplayAdapters[adapterToUse].adapter,

        //If we failed
		std::cout<<"Failed to create the Direct X device. HR Error: "<<hr<<std::endl;
		return false;

	return true;

What am I doing wrong?

I'm not really sure why this is happening, the hr error code printed out is -2147024809

Edited by noodleBowl

Share this post

Link to post
Share on other sites

If you specify an adapter as the first parameter of D3D11CreateDevice, then you have to pass D3D_DRIVER_TYPE_UNKNOWN as the driver type. I believe the docs for D3D11CreateDevice say this if you read through the remarks section.

As for the error code, if you're using the old headers and libs from the June 2010 DirectX SDK you can use DXGetErrorString/DXGetErrorDescription to get the string name of an HRESULT. If you're using the new headers and libs from the Windows 8 or Windows 8.1 SDK, then you can use FormatMessage to get the string. Or if you want Chuck Walbourn provided replacements for the DX error functions on his blog. Either way in your case the error code is probably just going to be E_INVALIDARG, which isn't particularly helpful for figuring out what you did wrong. However if you pass D3D11_CREATE_DEVICE_DEBUG as the flags parameter of D3D11CreateDevice, then any further failing function calls after creating the device will output a detailed message in the debugger output window. You can also use the ID3D11Debug interface to make the runtime break on errors or warnings, which is pretty helpful. Just make sure you don't pass it for Release builds, since end-users typically won't have the debug runtimes installed on their system.

Edited by MJP

Share this post

Link to post
Share on other sites

If you specify an adapter as the first parameter of D3D11CreateDevice, then you have to pass D3D_DRIVER_TYPE_UNKNOWN as the driver type. I believe the docs for D3D11CreateDevice say this if you read through the remarks section.


<Other portions of quote>


While this is something to try out. Is it possible that because I use a "temp" DisplayAdapter struct and clean it up that I'm faced with null memory area?

Also maybe the scope of the "temp" object could be effecting it? Seeing as the method to find the adapters and the method to create the device are seperated


I would solve this using a deep copy but I'm unsure how to do this.  Especially since the struct includes pointers for the IDXGIAdapter COM object and array of DXGI_MODE_DESCs. Or am I just thinking wayout in left field?


Then at least I would know the error lies in the D3D_DRIVER_TYPE_UNKNOWN and not something else.

Edited by noodleBowl

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!