D3D11CreateDeviceAndSwapChain使Visual Studio无法使用

时间:2014-11-02 15:40:37

标签: visual-studio visual-studio-2013 directx-11 lag

大家好我有一个非常奇怪的问题。 当我从程序的开头逐步执行我的代码时它很好但是当我到达我的代码中的部分来创建设备和交换链时Visual Studio开始滞后于输入并变得不可用。我的鼠标也给出了真正的延迟响应。阻止它的唯一方法是ctrl + alt + del并关闭Visual Studio。

以下是相关行的代码。

HRESULT hr = S_OK;

RECT rc;
GetClientRect((*pWindowHandle), &rc);
UINT width = rc.right - rc.left;
UINT height = rc.bottom - rc.top;

UINT createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

D3D_DRIVER_TYPE driverTypes[] =
{
    D3D_DRIVER_TYPE_HARDWARE,
    D3D_DRIVER_TYPE_WARP,
    D3D_DRIVER_TYPE_REFERENCE,
};
UINT numDriverTypes = ARRAYSIZE(driverTypes);

D3D_FEATURE_LEVEL featureLevels[] =
{
    D3D_FEATURE_LEVEL_11_0
};
UINT numFeatureLevels = ARRAYSIZE(featureLevels);

DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory(&sd, sizeof(sd));
sd.BufferCount = 1;
sd.BufferDesc.Width = width;
sd.BufferDesc.Height = height;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = (*pWindowHandle);
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;     // allow full-screen switching

for (UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++)
{
    m_driverType = driverTypes[driverTypeIndex];
    hr = D3D11CreateDeviceAndSwapChain(NULL, m_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels,
        D3D11_SDK_VERSION, &sd, &m_pSwapChain, &m_pd3dDevice, &m_featureLevel, &m_pImmediateContext);
    if (SUCCEEDED(hr))
        break;
}

我觉得它可能与visual studio而不是项目有关,因为D3D11示例项目也是如此。他们运行正常,但一旦你试图暂停或打破VS就会摇摆不定。 我已经尝试修复我的VS2013 Update2版本

有什么东西可以帮助我吗?

从调试文件夹输出

Build started 02/11/2014 16:24:14.
     1>Project "C:\Users\luckielordie\Source\Repos\3dtut2\Tutorial02_2010.vcxproj" on node 2 (Build target(s)).
     1>ClCompile:
         C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /I..\..\..\DXUT11\Core /I..\..\..\DXUT11\Optional /ZI /nologo /W4 /WX- /Od /Oi /Oy- /D WIN32 /D _DEBUG /D DEBUG /D PROFILE /D _WINDOWS /D D3DXFX_LARGEADDRESS_HANDLE /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /arch:SSE2 /fp:fast /Zc:wchar_t /Zc:forScope /openmp- /Fo"Debug\\" /Fd"Debug\vc120.pdb" /Gd /TP /analyze- /errorReport:prompt  D3D11.cpp
         D3D11.cpp
       Link:
         C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\luckielordie\Source\Repos\3dtut2\Debug\D3DApplication.exe" /INCREMENTAL /NOLOGO d3d11.lib d3dcompiler.lib dxguid.lib winmm.lib comctl32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /manifestinput:"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\Include\Manifest\dpiaware.manifest" /DEBUG /PDB:"C:\Users\luckielordie\Source\Repos\3dtut2\Debug\D3DApplication.pdb" /SUBSYSTEM:WINDOWS /LARGEADDRESSAWARE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\luckielordie\Source\Repos\3dtut2\Debug\D3DApplication.lib" /MACHINE:X86 /SAFESEH  /SAFESEH:NO Debug\Tutorial02.res
         Debug\D3D11.obj
         Debug\D3D11ResourceBuilder.obj
         Debug\Game.obj
         Debug\GameObject.obj
         Debug\main.obj
         Debug\Model.obj
         Debug\Shader.obj
         Debug\Window.obj
         Tutorial02_2010.vcxproj -> C:\Users\luckielordie\Source\Repos\3dtut2\Debug\D3DApplication.exe
     1>Done Building Project "C:\Users\luckielordie\Source\Repos\3dtut2\Tutorial02_2010.vcxproj" (Build target(s)).

Build succeeded.

Time Elapsed 00:00:01.42

编辑: 在输出中的那一行我得到一行

A thread <threadnumber> has exited with code 0(0x0)

1 个答案:

答案 0 :(得分:0)

我有完全相同的问题,它通过更新视频驱动程序解决(我有nVidia GeForce 660,现在我使用344.75,我使用&#34安装它;清洁&#34;选项)。以前的车手是335或者什么的。此外,如果它没有帮助,尝试禁用nVidia ShadowPlay(虽然它没有帮助我),我认为如果它在D3D中安装了一些键盘钩,那么可能存在一些问题。