DirectX10交换链和设备指向0x00000000(导致运行时错误)(c+;+;) >,我跟着(代码在页面下面,你可以点击显示代码的顶部)关于DX10和C++ 基本上代码是这样的 // include and stuff ID3D10Device* device; // adding = NULL wont change problem ID3D10RenderTargetView* rtv; IDXGISwapChain* swapchain; // function predecs, winmain, winproc // winmain calls initD3D(hWnd) just before entering msg loop void initD3D(HWND hWnd){ DXGI_SWAP_CHAIN_DESC scd; // creates struct for swap chain info ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC)); // clear the struct for use scd.BufferCount = 1; // create two buffers one front buffer one back buffer scd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // use 32-bit color scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // tell how chain is to be used scd.OutputWindow = hWnd; // set window to be used by d3d scd.SampleDesc.Count = 1; // set level of multi sampling scd.SampleDesc.Quality = 0; // set quality of multisampling scd.Windowed = true; // set to windowed or fullscreen D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &scd, &swapchain, &device); // get the adress of the backbuffer and use it to create the render target ID3D10Texture2D* pBackBuffer; // AND HERE (NEXT LINE) THE ERROR OCCURS swapchain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer); // on runtime debugger tells me swapchain value is 0x00000000 // why does it point to nowhere? device->CreateRenderTargetView(pBackBuffer, NULL, &rtv); pBackBuffer->Release(); // set the render target as the back buffer device->OMSetRenderTargets(1, &rtv, NULL); D3D10_VIEWPORT viewport; // create a struct to hold the viewport data ZeroMemory(&viewport, sizeof(D3D10_VIEWPORT)); // clear the struct //viewport.stuff device->RSSetViewports(1, &viewport); //set the viewport

DirectX10交换链和设备指向0x00000000(导致运行时错误)(c+;+;) >,我跟着(代码在页面下面,你可以点击显示代码的顶部)关于DX10和C++ 基本上代码是这样的 // include and stuff ID3D10Device* device; // adding = NULL wont change problem ID3D10RenderTargetView* rtv; IDXGISwapChain* swapchain; // function predecs, winmain, winproc // winmain calls initD3D(hWnd) just before entering msg loop void initD3D(HWND hWnd){ DXGI_SWAP_CHAIN_DESC scd; // creates struct for swap chain info ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC)); // clear the struct for use scd.BufferCount = 1; // create two buffers one front buffer one back buffer scd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // use 32-bit color scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // tell how chain is to be used scd.OutputWindow = hWnd; // set window to be used by d3d scd.SampleDesc.Count = 1; // set level of multi sampling scd.SampleDesc.Quality = 0; // set quality of multisampling scd.Windowed = true; // set to windowed or fullscreen D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &scd, &swapchain, &device); // get the adress of the backbuffer and use it to create the render target ID3D10Texture2D* pBackBuffer; // AND HERE (NEXT LINE) THE ERROR OCCURS swapchain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer); // on runtime debugger tells me swapchain value is 0x00000000 // why does it point to nowhere? device->CreateRenderTargetView(pBackBuffer, NULL, &rtv); pBackBuffer->Release(); // set the render target as the back buffer device->OMSetRenderTargets(1, &rtv, NULL); D3D10_VIEWPORT viewport; // create a struct to hold the viewport data ZeroMemory(&viewport, sizeof(D3D10_VIEWPORT)); // clear the struct //viewport.stuff device->RSSetViewports(1, &viewport); //set the viewport,c++,windows,visual-studio-2010,directx,C++,Windows,Visual Studio 2010,Directx,} 我省略了不必要的代码,我认为您可以找到它,或者如果您真的需要完整的代码,可以按照链接进行操作,我想重点关注主要问题;) 因此,正如代码中所述,我的调试器告诉我,swapchain指向0x00000000,通过查看这些值,我发现它与device相同,也指向0x00000000。 信息是: First-chance exception at 0x........ in bla.exe: 0x........: Access violation reading location 0x0000000

}

我省略了不必要的代码,我认为您可以找到它,或者如果您真的需要完整的代码,可以按照链接进行操作,我想重点关注主要问题;)

因此,正如代码中所述,我的调试器告诉我,
swapchain
指向0x00000000,通过查看这些值,我发现它与
device
相同,也指向0x00000000。 信息是:

First-chance exception at 0x........ in bla.exe: 0x........: Access violation reading location 0x00000000
我查看了整个代码,不知道可能是什么问题

这可能是硬件相关的问题吗? 我在ThinkPad T510上,有两个图形芯片(一个英特尔和一个英伟达),使用NVIDIA芯片作为默认原因导致VisualStudio崩溃。 我不知道还有什么问题,因为教程说明代码将运行:) 我知道还有另一个话题与一个非常相关的问题,但据我所知,它并不相同。(作者给自己的答案并不能解决我的问题)

编辑:我刚刚读取调试输出,似乎无法加载**加载的*.dll 顺便说一句,我使用的是DXSDK的x86库

片段:

'AnotherWindowsApp.exe': Loaded 'E:\visual studio 2010 Projects\AnotherWindowsApp\Debug\AnotherWindowsApp.exe', Symbols loaded.
'AnotherWindowsApp.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'AnotherWindowsApp.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'AnotherWindowsApp.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
[...]
'AnotherWindowsApp.exe': Loaded 'C:\Windows\SysWOW64\nvinit.dll', Binary was not built with debug information.
'AnotherWindowsApp.exe': Loaded 'C:\Program Files (x86)\NVIDIA Corporation\coprocmanager\detoured.dll', Cannot find or open the PDB file
'AnotherWindowsApp.exe': Loaded 'C:\Program Files (x86)\NVIDIA Corporation\coprocmanager\Nvd3d9wrap.dll', Cannot find or open the PDB file
[...]
'AnotherWindowsApp.exe': Loaded 'C:\Windows\SysWOW64\d3d9.dll', Cannot find or open the PDB file
'AnotherWindowsApp.exe': Loaded 'C:\Program Files (x86)\NVIDIA Corporation\coprocmanager\nvdxgiwrap.dll', Cannot find or open the PDB file
'AnotherWindowsApp.exe': Loaded 'C:\Windows\SysWOW64\d3d11.dll', Cannot find or open the PDB file
[...]
'AnotherWindowsApp.exe': Loaded 'C:\Windows\SysWOW64\igd10umd32.dll', Cannot find or open the PDB file
First-chance exception at 0x7623b727 in AnotherWindowsApp.exe: Microsoft C++ exception: _com_error at memory location 0x0045f06c..
First-chance exception at 0x7623b727 in AnotherWindowsApp.exe: Microsoft C++ exception: _com_error at memory location 0x0045ef90..
First-chance exception at 0x7623b727 in AnotherWindowsApp.exe: Microsoft C++ exception: _com_error at memory location 0x0045f0e0..
The thread 'Win32 Thread' (0x18b0) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x12dc) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x354) has exited with code 0 (0x0).
The thread 'UMDShimPresentThread' (0x1080) has exited with code 0 (0x0).
'AnotherWindowsApp.exe': Unloaded 'C:\Windows\SysWOW64\nvwgf2um.dll'
'AnotherWindowsApp.exe': Unloaded 'C:\Windows\SysWOW64\igd10umd32.dll'
First-chance exception at 0x01281758 in AnotherWindowsApp.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x01281758 in AnotherWindowsApp.exe: 0xC0000005: Access violation reading location 0x00000000.
First-chance exception at 0x01281758 in AnotherWindowsApp.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x01281758 in AnotherWindowsApp.exe: 0xC0000005: Access violation reading location 0x00000000.
The program '[5912] AnotherWindowsApp.exe: Native' has exited with code -1073741819 (0xc0000005).

首先,您应该检查D3D10CreateDeviceAndSwapChain函数返回的错误代码。将错误代码与上面的代码进行比较,首先了解可能出了什么问题

D3D10CreateDeviceAndSwapChain函数未成功时,“swapchain”和“device”设置为零(0x00000000)

其次,根据DXGI_SWAP_CHAIN_DESC struct是一个“in”参数。 可能是这导致了你的错误

更新(根据评论):
与本教程不同的一点是缓冲区格式。本教程使用DXGI_格式,但您使用的是DXGI_格式,而您使用的是DXGI_格式。

考虑打开D3D调试输出,它肯定会告诉您在
D3D10CreateDeviceAndSwapChain

发生这种情况是因为
D3D10CreateDeviceAndSwapChain
失败。您没有检查返回代码。例如,您试图创建D3D10硬件设备,但可能未使用D3D10级图形硬件运行。使用Direct3D调试输出告诉您错误是什么。

您应该检查D3D10CreateDeviceAndSwapChain函数返回的错误代码。@PetPaulsen:这是问题的有效答案。
D3D10CreateDeviceAndSwapChain()
调用失败。所以,你应该把它作为一个答案发布。我从来没有做过与DirectX相关的事情,但是锁定文档,你不负责填写DXGI_SWAP_CHAIN_DESC struct吗?我不知道为什么我只是复制并粘贴网站上的全部代码。。。现在它开始工作了。唯一的区别是,这次我包括了来自DXSDK的x64 lib和x86 lib。。。编辑:即使没有x64库,它也可以工作。。。现在一切都在错误查找中。不同的是缓冲区格式。本教程使用DXGI_格式\u r8g8a8_UNORM,但您使用的是DXGI_格式\u B8G8R8A8_UNORM。我想这只是在代码段中记录的:
一些设置scd的内容。参数如下所示
。然而,错误的参数是最有可能的原因,因此最好能看到它们。正如在注释(在代码中)中所写的,它实际上在代码中,但对我来说,它带走了问题的焦点,所以我忽略了它。参数与上面的完全一样,我将把它重新编辑到上面的代码中,我不知道它可能与问题有多大关系。是的,我知道,我真的试图理解directX,所以我创建了大量的注释,问自己我在那里做了什么。如果它们太烦人,我可以把它们编辑出来,我只是简单地添加了将D3D10CreateTuff的输出放在一个HRESULT中(正如我在下面的antoher评论中所说的),并添加了
if(FAILED(hr)){return;}
,现在我被踢出了那里,运行时无法销毁交换链(它应该怎么做,从来没有出现过)。非常感谢,但我该如何解决这个问题呢?你在信中写道,你将使用英特尔芯片作为默认芯片。当你切换到英伟达芯片时会发生什么?也许英特尔芯片不支持DX10。编辑:只需阅读你对另一个答案的评论。。。你已经有了这个想法,我太慢了…我在D3D10CreateDevice前面添加了
HRESULT hr=
,但是如果我尝试添加
if(FAILED(hr))抛出GXVideoException(L“检索directX设备时出现问题”)
i get
GXVideoException:identifier not found
我在这里遗漏了哪些内容?编辑:我很愚蠢。。。很抱歉没有try-catch块,所以我可能只添加一个,正如我所说的,我在双图形卡系统上运行,可能有什么问题。3D芯片是一款NVIDIA®Quadro®NVS3100M,能够使用DX10,但我认为该程序试图在Intel适配器上运行