hr = D3D10CreateDeviceAndSwapChain returns -2005270527

I have been bashing my head on the keyboard for 3 days over this it is just driving me insane. when I call D3D10CreateDeviceAndSwapChain hr = -2005270527.

I get no errors on build.

I may have done some thing stupid but I can't see it. most of the code is from the dx10 tutorials.

I am using vs2008 and DirectX SDK (November 2008)

I moved the definitions for g_pd3dDevice,g_pSwapChain to see if something was wrong with that but no luck.

Pleas Help

My Device.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "MyDevice.h"
#include "MyWindow.h"


MyDevice::MyDevice(ID3D10Device* g_pd3dDevice, IDXGISwapChain* g_pSwapChain)
{
	
	
	g_driverType = D3D10_DRIVER_TYPE_NULL;
	//g_pd3dDevice = NULL;
	//g_pSwapChain = NULL;
	g_pRenderTargetView = NULL;

}

HRESULT MyDevice::InitDevice(RECT rc,ID3D10Device* g_pd3dDevice, IDXGISwapChain* g_pSwapChain)
{
	HRESULT hr = S_OK;;

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

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

	D3D10_DRIVER_TYPE driverTypes[] =
	{
		D3D10_DRIVER_TYPE_HARDWARE,
		D3D10_DRIVER_TYPE_REFERENCE,
	};
	UINT numDriverTypes = sizeof( driverTypes ) / sizeof( driverTypes[0] );

	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 = g_hWindow;
	sd.SampleDesc.Count = 1;
	sd.SampleDesc.Quality = 0;
	sd.Windowed = TRUE;

	for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
	{
		g_driverType = driverTypes[driverTypeIndex];
		hr = D3D10CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags,
                                            D3D10_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice );
		if( SUCCEEDED( hr ) )
			break;
	}
	if( FAILED( hr ) )
		return hr;

	// Create a render target view
	ID3D10Texture2D* pBackBuffer;
	hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D10Texture2D ), ( LPVOID* )&pBackBuffer );
	if( FAILED( hr ) )
		return hr;

	hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView );
	pBackBuffer->Release();
	if( FAILED( hr ) )
		return hr;

	g_pd3dDevice->OMSetRenderTargets( 1, &g_pRenderTargetView, NULL );

	// Setup the viewport
	D3D10_VIEWPORT vp;
	vp.Width = width;
	vp.Height = height;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	g_pd3dDevice->RSSetViewports( 1, &vp );

	return S_OK;
}


//--------------------------------------------------------------------------------------
// Render the frame
//--------------------------------------------------------------------------------------
void MyDevice::Render(ID3D10Device* g_pd3dDevice, IDXGISwapChain* g_pSwapChain)
{
	// Just clear the backbuffer
	float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; //red,green,blue,alpha
	g_pd3dDevice->ClearRenderTargetView( g_pRenderTargetView, ClearColor );
	g_pSwapChain->Present( 0, 0 );
}


//--------------------------------------------------------------------------------------
// Clean up the objects we've created
//--------------------------------------------------------------------------------------
void MyDevice::CleanupDevice(ID3D10Device* g_pd3dDevice, IDXGISwapChain* g_pSwapChain)
{
	if( g_pd3dDevice ) g_pd3dDevice->ClearState();

	if( g_pRenderTargetView ) g_pRenderTargetView->Release();
	if( g_pSwapChain ) g_pSwapChain->Release();
	if( g_pd3dDevice ) g_pd3dDevice->Release();
}

MyDevice.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

#ifndef MYDEVICE_H
#define MYDEVICE_H

#include <windows.h>
#include <d3d10.h>
#include <d3dx10.h>
#include "resource.h"

class MyDevice
{
public:
	struct SimpleVertex
{
    D3DXVECTOR3 Pos;
};


	HWND g_hWindow;

	D3D10_DRIVER_TYPE       g_driverType ;
	//ID3D10Device*           g_pd3dDevice ;
	//IDXGISwapChain*         g_pSwapChain ;
	ID3D10RenderTargetView* g_pRenderTargetView ;
	ID3D10Effect*           g_pEffect;
	ID3D10EffectTechnique*  g_pTechnique;
	ID3D10InputLayout*      g_pVertexLayout;
	ID3D10Buffer*           g_pVertexBuffer;

	MyDevice(ID3D10Device* g_pd3dDevice, IDXGISwapChain* g_pSwapChain);
	HRESULT InitDevice(RECT rc,ID3D10Device* g_pd3dDevice, IDXGISwapChain* g_pSwapChain);
	void Render(ID3D10Device* g_pd3dDevice, IDXGISwapChain* g_pSwapChain);
	void CleanupDevice(ID3D10Device* g_pd3dDevice, IDXGISwapChain* g_pSwapChain);

};

#endif 


Main.CPP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "MyWindow.h"
#include "MessegeCallBack.h"
#include "MyDevice.h"

//--------------------------------------------------------------------------------------
// Entry point to the program. Initializes everything and goes into a message processing 
// loop. Idle time is used to render the scene.
//--------------------------------------------------------------------------------------
ID3D10Device*           g_pd3dDevice = NULL;
IDXGISwapChain*         g_pSwapChain = NULL;
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
{
	MyWindow *myWindow = new MyWindow();
	MyDevice *myDevice = new MyDevice(g_pd3dDevice,g_pSwapChain);

	if( FAILED( myWindow->InitWindow ( hInstance, nCmdShow ) ) ){return 0;}
	if( FAILED( myDevice->InitDevice (myWindow->GetRECT(),g_pd3dDevice,g_pSwapChain)))
	{
		return 0;
	}


    // Main message loop
    MSG msg = {0};
    while( GetMessage( &msg, NULL, 0, 0 ) )
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }
	 
    return ( int )msg.wParam;
}
Does your OS have DX10 installed? Does your video card and operating system support DX10?
yes i have dx10 installed. You need it to compile. and yes my video card supports dx10.

i can run all my other dx10 code just not this one.

at runtime

hr = D3D10CreateDeviceAndSwapChain (NULL, g_driverType, NULL, createDeviceFlags,
D3D10_SDK_VERSION, &sd, &g_pSwapChain, );
hr = -2005270527


Topic archived. No new replies allowed.