简体   繁体   English

DirectX10交换链和设备指向0x00000000(导致运行时错误)(C ++)

[英]DirectX10 swapchain and device point to 0x00000000 (causing runtime error) (c++)

Ok, i followed this tutorial (code is down below on the page, just top of the picture you can click on show code) about DX10 and c++ basically the code is like 好的,我遵循了关于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

} }

i left out the unnecessary code, I think you can either figure it out or follow the link if you really need the full code, I want to focus on the main problem ;) 我省去了不必要的代码,如果您确实需要完整的代码,我想您可以找出答案或单击链接,我想关注主要问题;)

so as stated in the code my debugger tells me that swapchain points to 0x00000000 looking through the values i found out that its the same with device also poinmts to 0x00000000. 所以在代码中说了自己的调试器告诉我, swapchain点到00000000翻翻,我发现,它与相同的价值观device也poinmts到00000000。 Message is: 消息是:

First-chance exception at 0x........ in bla.exe: 0x........: Access violation reading location 0x00000000

i looked over the whole code, have no idea what might be the problem. 我查看了整个代码,不知道可能是什么问题。

could it be a hardware related problem? 可能是与硬件相关的问题吗? I am on a Thinkpad T510 with two graphics chips (one intel and one nVidia), using the nVidia chips as default causes Visual Studio to crash. 我正在使用具有两个图形芯片(一个英特尔和一个nVidia)的Thinkpad T510,默认情况下使用nVidia芯片会导致Visual Studio崩溃。

i have no idea what else might be the problem, because the tutorial states that the code will run :) i know that there is another topic with a very very related problem, but as far as i understand its not the same. 我不知道还有什么可能是问题,因为本教程指出该代码将运行:)我知道还有另一个主题与非常非常相关的问题,但是据我了解,它并不相同。 (and the answer the author gave himself doesn't solve my problem) (作者给出的答案并不能解决我的问题)

edit: i just read debug output and it seems that a * *load of *.dlls couldn't be loaded btw I am using the x86 libs of DX SDK 编辑:我只是读取调试输出,似乎无法加载* .dll的* *负载我正在使用DX SDK的x86库

snippet: 片段:

'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).

First you should check what error code is returned by the D3D10CreateDeviceAndSwapChain function. 首先,您应该检查D3D10CreateDeviceAndSwapChain函数返回的错误代码。 Compare the error code with the ones on this site to get a first idea, what may have gone wrong. 将错误代码与该网站上的错误代码进行比较,以了解第一个想法,可能是哪里出错了。

'swapchain' and 'device' are set to zero (0x00000000), when the D3D10CreateDeviceAndSwapChain function wasn't successful. 当D3D10CreateDeviceAndSwapChain函数不成功时,“ swapchain”和“ device”设置为零(0x00000000)。

Second, according to the docs the DXGI_SWAP_CHAIN_DESC struct is an 'in' parameter. 其次,根据文档 ,DXGI_SWAP_CHAIN_DESC结构是“ in”参数。 Probably this causes your error. 可能这会导致您的错误。

Update (Based on the comments): One thing thats different to the tutorial is the Buffer Format. 更新 (基于评论):与本教程不同的一件事是缓冲区格式。 The tutorial uses DXGI_FORMAT_R8G8B8A8_UNORM but you used DXGI_FORMAT_B8G8R8A8_UNORM. 本教程使用DXGI_FORMAT_R8G8B8A8_UNORM,但是您使用了DXGI_FORMAT_B8G8R8A8_UNORM。

考虑打开D3D调试输出,它肯定会告诉您D3D10CreateDeviceAndSwapChain什么问题。

This occurs because D3D10CreateDeviceAndSwapChain fails. 这是因为D3D10CreateDeviceAndSwapChain失败。 You didn't check the return code. 您没有检查返回码。 You attempted to create a D3D10 hardware device but may not be running with D3D10-level graphics hardware, for example. 例如,您试图创建D3D10硬件设备,但可能没有与D3D10级图形硬件一起运行。 Use the Direct3D debug output to tell you what the error was. 使用Direct3D调试输出可以告诉您错误所在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM