问题描述:

I started to lean c++ and directx11 a few days back.

So I am no expert at it. .Please be kind enough to explain me why it had occurred ...

I created the window and stuff correctly.Even the Swapchain initializtion proceeded as expected.But I am stuck at render Targetview Initializtion...

When ever i debug it gives me the following error

 dxgiDevice 0x008959ac <Information not available, no symbols loaded for d3d11.dll> IDXGIDevice

I dont know what am I doing wrong here.I have included Static libraries(dxgi.lib

d3dx11.lib

d3d11.lib

dxguid.lib

D3DCompiler.lib) and linked correctly the header files and libraries as well..

The error seems to arise from this line

 SwapChain->GetBuffer(0,__uuidof(ID3D11Texture2D),(LPVOID*)(&backBuffer));

I dont know what to do..It has gotten me really frustrated.

Please do help me out here..I will be very thank full

Thanks

Here is the full code

#include <Windows.h>

#include <windowsx.h>

#include <D3D11.h>

#include <D3DX11.h>

#include <D3DX10.h>

using namespace std;

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

bool InitWindowClass(HINSTANCE hinst,int shw,HWND * _hwnd,WNDCLASSEX * exClass);

RECT windowWidth = {0,0, 1000,768};

int WINAPI WinMain(HINSTANCE inst,HINSTANCE previnst,LPSTR cmdLine,int show)

{

// Window Params

HWND hwnd;

WNDCLASSEX exClass;

MSG msg;

// Iniitaliztion

SecureZeroMemory(&hwnd,sizeof(HWND));

SecureZeroMemory(&exClass,sizeof(exClass));

SecureZeroMemory(&msg,sizeof(MSG));

// Directx 11 Functionalities

#pragma region Create the device

D3D_FEATURE_LEVEL featureLevels[4] = {D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1 , D3D_FEATURE_LEVEL_10_0 , D3D_FEATURE_LEVEL_9_1};

D3D_FEATURE_LEVEL feature_LEVEL;

ID3D11Device * d3dDevice = 0;

ID3D11DeviceContext * d3dContext = 0;

HRESULT hr = D3D11CreateDevice(0,

D3D_DRIVER_TYPE_HARDWARE,

0,

0, // No flags

featureLevels,4,

D3D11_SDK_VERSION,

&d3dDevice,

&feature_LEVEL,&d3dContext);

if(FAILED(hr))

{

MessageBox(hwnd,L"FAiled TO CREATE DEVICE",L"ERROR",0);

}

#pragma endregion

#pragma region Multisampling

UINT multisampleQuality;

d3dDevice->CheckMultisampleQualityLevels(DXGI_FORMAT_B8G8R8A8_UNORM,4,&multisampleQuality);

#pragma endregion

#pragma region DescribeSwapChain

DXGI_SWAP_CHAIN_DESC swapDesc;

// Allocate Mommory

SecureZeroMemory(&swapDesc,sizeof(DXGI_SWAP_CHAIN_DESC));

swapDesc.BufferDesc.Width = 1000;

swapDesc.BufferDesc.Height = 768;

swapDesc.BufferDesc.RefreshRate.Numerator= 60;

swapDesc.BufferDesc.RefreshRate.Denominator = 1;

swapDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;

swapDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;

swapDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

//MSAA

swapDesc.SampleDesc.Count = 4;

swapDesc.SampleDesc.Quality = multisampleQuality;

//BackBuffer

swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;

swapDesc.BufferCount = 1;

swapDesc.OutputWindow = hwnd;

swapDesc.Windowed = true;

swapDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

swapDesc.Flags = 0;

#pragma endregion

#pragma region CreateSwapChain

#pragma region Obtain DXGIFactory

// DXGIFactory >> DXGIAdaptor >> DXGIDevice

// Get the DXGI device

IDXGIDevice * dxgiDevice = 0;

d3dDevice->QueryInterface(__uuidof(IDXGIDevice),(void**)&dxgiDevice);

// Obtain DXGIAdaptor

IDXGIAdapter * dxgiAdaptor = 0;

dxgiDevice->GetParent(__uuidof(IDXGIAdapter),(void**)&dxgiAdaptor);

IDXGIFactory * dxgiFactory = 0;

dxgiAdaptor->GetParent(__uuidof(IDXGIFactory),(void**)&dxgiFactory);

#pragma endregion

IDXGISwapChain * SwapChain = 0;

SecureZeroMemory(&SwapChain,sizeof(IDXGISwapChain));

dxgiFactory->CreateSwapChain(d3dDevice,&swapDesc,&SwapChain);

dxgiAdaptor->Release();

dxgiDevice->Release();

dxgiFactory->Release();

#pragma endregion

#pragma region Create Render Target View

ID3D11RenderTargetView * RenderTarget = 0;

ID3D11Texture2D * backBuffer = 0;

SwapChain->GetBuffer(0,__uuidof(ID3D11Texture2D),(LPVOID*)(&backBuffer));

d3dDevice->CreateRenderTargetView(backBuffer,NULL,&RenderTarget);

backBuffer->Release();

#pragma endregion

if(InitWindowClass(inst,show,&hwnd,&exClass))

{

while(msg.message != WM_QUIT)

{

if(PeekMessage(&msg,hwnd,0,0,PM_REMOVE))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}else{

// Update Sequences

}

}

}

return msg.wParam;

}

// Initialize and show the Window

bool InitWindowClass(HINSTANCE hinst,int shw,HWND * _hwnd,WNDCLASSEX * exClass)

{

HWND hwnd2 ;

SecureZeroMemory(&hwnd2,sizeof(HWND));

exClass->cbSize = sizeof(WNDCLASSEX);

exClass->hCursor = LoadCursor(0,IDC_ARROW);

exClass->hInstance = hinst;

exClass->lpfnWndProc = WndProc;

exClass->lpszClassName = L"DX_Test";

exClass->lpszMenuName = L"Test";

exClass->hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);

RegisterClassEx(exClass);

AdjustWindowRect(&windowWidth,WS_OVERLAPPEDWINDOW,false);

(*_hwnd) = CreateWindowEx(0,L"DX_Test",L"Test",WS_OVERLAPPEDWINDOW,500,200,windowWidth.left,windowWidth.top,NULL,NULL,hinst,0);

ShowWindow((*_hwnd),shw);

UpdateWindow(*_hwnd);

return true;

}

// Message Loop

LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)

{

switch (msg)

{

case WM_LBUTTONDBLCLK:

MessageBox(hwnd,L"Prressed Button 1",L"Mouse 1",0);

return 0;

break;

case WM_DESTROY:

PostQuitMessage(0);

return 0;

break;

case WM_KEYDOWN:

if(wparam == VK_ESCAPE)

DestroyWindow(hwnd);

return 0;

}

return DefWindowProc(hwnd,msg,wparam,lparam);

}

网友答案:

The "error message" you're talking about comes from the VS debugger: all it is telling you is that it doesn't have any debugging symbols for d3d11.dll. In other words this is not your problem - it's a red herring.

To solve the problem, you need some error checking. IDXGISwapChain::GetBuffer returns a HRESULT, which you should check for errors, e.g.:

HRESULT res = SwapChain->GetBuffer(...);
if (!SUCCEEDED(res))
{
    std::cerr << "Error getting buffer from swap chain: " << std::hex << res << std::endl;
}

You can then check the result against the values in this set of documentation to find out specifically what the error was.

Note that you should probably do similar things for a lot of your other DirectX calls as well.

相关阅读:
Top