Program exits at Direct3D initialization (D3D11CreateDevice)

Started by
1 comment, last by Nick C. 11 years, 5 months ago
Hello everyone

About a week ago I've started reading "3D game programming with DirectX 11" by Frank D. Luna. After a few days I came at the point of the initialization. It took me a while to get everything to work properly (linking libraries (especially Effects11.lib) and including wrong paths), but eventually it worked. But all of a sudden (that's what I'm here for, possible causes smile.png), not one of my projects works anymore. In each of my projects the program exits at the same line: D3D11CreateDevice. Using breakpoints, I can't step into the line. I don't get any errors or warnings.

The values of the datamembers, just before execution of this method are:

md3dDriverType = D3D_DRIVER_TYPE_HARDWARE;
createDeviceFlags = 2; (changed from 0 to 2 at the preceding instruction)
D3D11_SDK_VERSION: speaks for itself. (7 possibilities ofcourse)
&md3dDevice, and &md3dImmediateContext: 0X00000000;
&featureLevel: some random address;

Any possible causes would be appreciated smile.png
Btw, I've already reinstalled directx sdk (June 2010), after some problems.

[source lang="cpp"]bool D3DApp::InitDirect3D()
{
// Create the device and device context.

UINT createDeviceFlags = 0;
#if defined(DEBUG) || defined(_DEBUG)
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

D3D_FEATURE_LEVEL featureLevel;
HRESULT hr = D3D11CreateDevice(
0, // default adapter
md3dDriverType,
0, // no software device
createDeviceFlags,
0, 0, // default feature level array
D3D11_SDK_VERSION,
&md3dDevice,
&featureLevel,
&md3dImmediateContext);

//...remaining thing to do
}[/source]


Edit: Sigh, even code tags don't work -.-
Edit2: Damnit, I don't know anymore, recreated project (new projects, but dragged same files), and now I'm getting the same error I got a few hours ago:
"warning LNK4204: 'C:\Nick\D3D projects\DVD\Code\Test\Debug\vc100.pdb' is missing debugging information for referencing module; linking object as if no debug info C:\Nick\D3D projects\DVD\Code\Test\Effects11d.lib(d3dx11dbg.obj)"

14 warnings. Alle possible solutions I found from google didn't help.
Advertisement
Hi Nick,

Using a default adapter doesn't work for me either. Perhaps just try to iterate the adapters. (In case you have multiple graphics cards, try to build a device on each and see which one has the best feature level.)


bool D3D::CreateDevice()
{
// Get the factory, so we can iterate the adapters and later build a swap chain.
if(FAILED(CreateDXGIFactory(__uuidof(IDXGIFactory) ,(void**)&_Factory)))
_Factory = NULL;
HRESULT hr = S_OK;
UINT createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_UNKNOWN,
};
UINT numDriverTypes = sizeof( driverTypes ) / sizeof( driverTypes[0] );
D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0 };
unsigned int numFeatureLevels = 3;

// Iterate the driver types (chose the first one that works. -> possible to use software fallback)
for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
{
_DriverType = driverTypes[driverTypeIndex];
// Iterate the adapters
for ( UINT i = 0;
_Factory->EnumAdapters(i, &_Adapter) != DXGI_ERROR_NOT_FOUND;
++i )
{
// Try to create a device
hr = D3D11CreateDevice(_Adapter, _DriverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &_Device, &_FeatureLevel, &_ImmediateContext);
if (SUCCEEDED(hr)) // pick the first that works (this is not necessarily the best one!)
break;
}
if( SUCCEEDED( hr ) )
break;
}
return true;
}


As for the debug info: do you have built the effect framework on debug and release, and link the correct version respectively?

Best regards,
Tsus
Thanks for the answer Tsus, however I've already solved my two problems (but I'll keep your code in mind, might come in handy in the future :)).

As for the LNK4204 warning, I rebuilt the solution in "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Samples\C++\Effects11" under debug mode, copied it to my project's directory and linked the correct libraries (which I did so many times...).
But the biggest problem was in fact, only a few Direct3D11 methods could be used properly. As pure frustration, I reinstalled my graphics driver, and it works perfectly now! :)
(don't ask why, how can drivers change by themselves..)

Anyway, thanks for the help, and sorry I posted this topic, but I just wanted some help badly, after hours and hours of messing around.

This topic is closed to new replies.

Advertisement