D3D11CreateDeviceAndSwapChain创建失败
今天程序突然跑步起来,诡异之极啊,说我的Device创建失败,之前还好好的呢,最后找出原因。
UINT createDeviceFlags = 0;#if defined(DEBUG) || defined(_DEBUG) createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;#endif// 创建驱动对象D3D11CreateDeviceAndSwapChain( NULL, D3D_DRIVER_TYPE_HARDWARE,//D3D_DRIVER_TYPE_REFERENCE,NULL, createDeviceFlags,&featureLevel, 1, D3D11_SDK_VERSION, &swapChainDesc, &mSwapChain, &mDevice, &mFeatureLevels, // 返回结果一直是 0 有毛用&mImmediateContext );
?问题就出现在createDeviceFlags这个参数
#if defined(DEBUG) || defined(_DEBUG) createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;#endif
?这个的意思是,让驱动支持debug,当然具体是神马就不清楚了。重要的是D3D11_CREATE_DEVICE_DEBUG 需要安装 Windows 8 SDK。
D3D11_CREATE_DEVICE_DEBUGCreates a device that supports the debug layer. To use this flag, you must have D3D11*SDKLayers.dll installed; otherwise, device creation fails. To get D3D11_1SDKLayers.dll, install the SDK for Windows 8.
?如果装的 VS2012,默认装 Windows 8 SDK,就没这个问题了。
解决办法就是注释掉这段代码