• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
thefatshizms

Direct x failing

11 posts in this topic

I have the following code:

HRESULT result = S_OK;
	ID3D11Device* g_pd3dDevice = NULL;
	IDXGISwapChain* g_pSwapChain = NULL;
	ID3D11DeviceContext* g_pImmediateContext = NULL;
	D3D_FEATURE_LEVEL	FeatureLevelsSupported;

	RECT deminsions;
	GetClientRect(hwnd, &deminsions);
	LONG width = deminsions.right - deminsions.left;
	LONG height = deminsions.top - deminsions.bottom;

	DXGI_SWAP_CHAIN_DESC sd;
	ZeroMemory( &sd, sizeof( sd ) );
	sd.BufferCount = 1;
	sd.BufferDesc.Width = static_cast<unsigned int>(width);
	sd.BufferDesc.Height = static_cast<unsigned int>(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 = hwnd;
	sd.SampleDesc.Count = 1;
	sd.SampleDesc.Quality = 0;
	sd.Windowed = TRUE;

	D3D_FEATURE_LEVEL FeatureLevelsRequested[] =
	{
		D3D_FEATURE_LEVEL_9_1,
		D3D_FEATURE_LEVEL_9_2,
		D3D_FEATURE_LEVEL_9_3,
		D3D_FEATURE_LEVEL_10_0,
		D3D_FEATURE_LEVEL_10_1,
		D3D_FEATURE_LEVEL_11_0
	};

	result = D3D11CreateDeviceAndSwapChain( NULL, 
                D3D_DRIVER_TYPE_HARDWARE, 
                NULL, 
                0,
                FeatureLevelsRequested, 
                3, 
                D3D11_SDK_VERSION, 
                &sd, 
                &g_pSwapChain, 
                &g_pd3dDevice, 
                &FeatureLevelsSupported,
                &g_pImmediateContext );

	if(FAILED(result)) return -1;


	ID3D11RenderTargetView* p_BackBufferTarget = NULL;
	ID3D11Texture2D* p_RT;

	result = g_pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&p_RT);
	if(FAILED(result)) return -2;

	result = g_pd3dDevice->CreateRenderTargetView(p_RT, 0, &p_BackBufferTarget);
	if(FAILED(result)) return -3;
	if(p_RT) p_RT->Release(); p_RT = NULL;
	g_pImmediateContext->OMSetRenderTargets(1, &p_BackBufferTarget, 0);

	D3D11_VIEWPORT viewport;
	viewport.Height = static_cast<float>(height);
	viewport.Width = static_cast<float>(width);
	viewport.MaxDepth = 1.0f;
	viewport.MinDepth = 0.0f;
	viewport.TopLeftX = 0.0f;
	viewport.TopLeftY = 0.0f;

	g_pImmediateContext->RSSetViewports(1, &viewport);

    UpdateWindow(hwnd);

the program fails and returns -1 which means there is something wrong with this:

result = D3D11CreateDeviceAndSwapChain( NULL, 
                D3D_DRIVER_TYPE_HARDWARE, 
                NULL, 
                0,
                FeatureLevelsRequested, 
                3, 
                D3D11_SDK_VERSION, 
                &sd, 
                &g_pSwapChain, 
                &g_pd3dDevice, 
                &FeatureLevelsSupported,
                &g_pImmediateContext );

But I'm not sure what?

 

Thanks, thefatshizms

0

Share this post


Link to post
Share on other sites

Try to create the device with the debug flag and check your output window and see what the error says.

0

Share this post


Link to post
Share on other sites
This may be a dull question, but do you have a dedicated graphics card that supports DX11? You may want to try D3D_DRIVER_TYPE_SOFTWARE as the second parameter...

Disclaimer: it's been a while since I used DirectX outside of C# though. So I may be way off base.
0

Share this post


Link to post
Share on other sites

I believe the problem is that when you are calculating the height, you should be doing (bottom - top), not (top - bottom).

 

Also, two other things:

  • You are passing in 3 as the feature level count to D3D11CreateDeviceAndSwapChain, meaning it will only look at the first 3 elements of your feature level array.
  • Your feature level array is backwards. It will attempt to use feature level 9.1 first, then 9.2, etc.
0

Share this post


Link to post
Share on other sites

Okay changed the height calculation, changed the feature level count to 6 and re arranged the array. Still crashes.

 

Using the debug flag now.. and this is the output :

'ITE.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\d3d11.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\dxgi.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'ITE.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\d3d10level9.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\setupapi.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\wintrust.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\crypt32.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\msasn1.dll', Cannot find or open the PDB file
'ITE.exe': Unloaded 'C:\Windows\SysWOW64\setupapi.dll'
'ITE.exe': Unloaded 'C:\Windows\SysWOW64\devobj.dll'
'ITE.exe': Unloaded 'C:\Windows\SysWOW64\oleaut32.dll'
'ITE.exe': Unloaded 'C:\Windows\SysWOW64\cfgmgr32.dll'
'ITE.exe': Loaded 'C:\Windows\SysWOW64\aticfx32.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\atiu9pag.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\atiumdag.dll', Cannot find or open the PDB file
'ITE.exe': Loaded 'C:\Windows\SysWOW64\atiumdva.dll', Cannot find or open the PDB file
First-chance exception at 0x760dc41f in ITE.exe: Microsoft C++ exception: _com_error at memory location 0x0024f520..
'ITE.exe': Unloaded 'C:\Windows\SysWOW64\atiumdva.dll'
'ITE.exe': Unloaded 'C:\Windows\SysWOW64\atiumdag.dll'
'ITE.exe': Unloaded 'C:\Windows\SysWOW64\aticfx32.dll'
'ITE.exe': Unloaded 'C:\Windows\SysWOW64\d3d10level9.dll'
First-chance exception at 0x00c417f1 in ITE.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x774215de in ITE.exe: 0xC0000005: Access violation reading location 0x00000000.

On the note that my graphics card might not be able to run direct x 11 .. I'm not actually sure on that.. I have a AMD Radeon HD something. I can run far cry 3 (which I think is directx 11).

0

Share this post


Link to post
Share on other sites

Have you tried stepping through with the debugger to ensure that things are behaving as expected? (ex. hwnd is not null, width and height have the expected values, etc.) Is it still failing at the same spot?

 

Also, you have this:

result = g_pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&p_RT);

I think you want ID3D11Texture2D there, not ID3D10Texture2D.

0

Share this post


Link to post
Share on other sites

Here is the full code:

 

/*
 
Window.h Creates and instalises direct x
*/
 
// make the window
#include <Windows.h>
 
// incude direct x 11
#pragma comment(lib, "d3d11.lib")
#include <d3d11.h>
 
// we need to use some math functions
#include <cmath>
 
 
// forward functions
bool InitializeDirect3dApp(HINSTANCE hInstance);
 
const char WindowClass[] = "GameWindow";
 
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}
 
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG msg;
 
wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = WindowClass;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
 
if(RegisterClassEx(&wc) == NULL) 
MessageBox(NULL, "ERROR : Failed to register the windows properties.", "ERROR", MB_ICONEXCLAMATION  | MB_OK);
 
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, WindowClass, "Inhabiting The Edge", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1100, 700, NULL, NULL, hInstance, NULL); 
 
if(hwnd == NULL)
MessageBox(NULL, "ERROR : Failed to create window.", "ERROR", MB_ICONEXCLAMATION | MB_OK);
 
 
HRESULT result = S_OK;
ID3D11Device* g_pd3dDevice = NULL;
IDXGISwapChain* g_pSwapChain = NULL;
ID3D11DeviceContext* g_pImmediateContext = NULL;
D3D_FEATURE_LEVEL FeatureLevelsSupported;
 
RECT deminsions;
GetClientRect(hwnd, &deminsions);
LONG width = deminsions.right - deminsions.left;
LONG height = deminsions.bottom - deminsions.top;
 
DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory( &sd, sizeof( sd ) );
sd.BufferCount = 1;
sd.BufferDesc.Width = static_cast<unsigned int>(width);
sd.BufferDesc.Height = static_cast<unsigned int>(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 = hwnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
 
D3D_FEATURE_LEVEL FeatureLevelsRequested[] =
{
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1
};
 
result = D3D11CreateDeviceAndSwapChain( NULL, 
                D3D_DRIVER_TYPE_HARDWARE, 
                NULL, 
                D3D11_CREATE_DEVICE_DEBUG,
                FeatureLevelsRequested, 
                6, 
                D3D11_SDK_VERSION, 
                &sd, 
                &g_pSwapChain, 
                &g_pd3dDevice, 
                &FeatureLevelsSupported,
                &g_pImmediateContext );
 
 
 
 
ID3D11RenderTargetView* p_BackBufferTarget = NULL;
ID3D11Texture2D* p_RT;
 
result = g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&p_RT);
if(FAILED(result)) return -2;
 
result = g_pd3dDevice->CreateRenderTargetView(p_RT, 0, &p_BackBufferTarget);
if(FAILED(result)) return -3;
if(p_RT) p_RT->Release(); p_RT = NULL;
g_pImmediateContext->OMSetRenderTargets(1, &p_BackBufferTarget, 0);
 
D3D11_VIEWPORT viewport;
viewport.Height = static_cast<float>(height);
viewport.Width = static_cast<float>(width);
viewport.MaxDepth = 1.0f;
viewport.MinDepth = 0.0f;
viewport.TopLeftX = 0.0f;
viewport.TopLeftY = 0.0f;
 
g_pImmediateContext->RSSetViewports(1, &viewport);
ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);
 
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
 
 
return msg.wParam;
 
}
0

Share this post


Link to post
Share on other sites

Is the issue resolved? Your code runs fine here. If not, which OS are you on?

0

Share this post


Link to post
Share on other sites

I'm on windows 7 ultimate(64 bit). If it runs okay on your system, it probably means I can't run direct x 11 or something :/

0

Share this post


Link to post
Share on other sites

I'm on windows 7 ultimate(64 bit). If it runs okay on your system, it probably means I can't run direct x 11 or something :/

Did you even try to debug it yourself before comming to this conclusion. Did you try to run any of the DX11 Samples and see whether it is using Hardware or Ref mode.

Edited by BornToCode
0

Share this post


Link to post
Share on other sites


Okay changed the height calculation, changed the feature level count to 6 and re arranged the array. Still crashes.

 

Your program didn't crash before. It returned -1. Why did you remove the return statement?

0

Share this post


Link to post
Share on other sites

 

I'm on windows 7 ultimate(64 bit). If it runs okay on your system, it probably means I can't run direct x 11 or something :/

Did you even try to debug it yourself before comming to this conclusion. Did you try to run any of the DX11 Samples and see whether it is using Hardware or Ref mode.

 

 

I didn't come to a conclusion.. I just think it might be a reason. What examples?

 


Okay changed the height calculation, changed the feature level count to 6 and re arranged the array. Still crashes.

 

Your program didn't crash before. It returned -1. Why did you remove the return statement?

 

 

 

I removed the return -1 because I wanted to see the message displayed when it failed.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0