DirectX 10 CreateDeviceAndSwapChain Fehler
-
Hallo,
ich bekomme beim Aufruf von D3D10CreateDeviceAndSwapChain(...) folgende Debugausgabe:D3D10: ERROR: ID3D10Device::CreateTexture2D: The Dimensions are invalid. The Width (value = -842150451) must be between 1 and 8192, inclusively. The Height (value = -842150451) must be between 1 and 8192, inclusively. And, the ArraySize (value = 1) must be between 1 and 512, inclusively. [ STATE_CREATION ERROR #101: CREATETEXTURE2D_INVALIDDIMENSIONS ] Eine Ausnahme (erste Chance) bei 0x763bb727 in Game VC++ 2008.exe: Microsoft C++-Ausnahme: _com_error an Speicherposition 0x0049ec1c.. D3D10: ERROR: ID3D10Device::CreateTexture2D: Returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #104: CREATETEXTURE2D_INVALIDARG_RETURN ] Eine Ausnahme (erste Chance) bei 0x763bb727 in Game VC++ 2008.exe: Microsoft C++-Ausnahme: _com_error an Speicherposition 0x0049ebbc.. Eine Ausnahme (erste Chance) bei 0x763bb727 in Game VC++ 2008.exe: Microsoft C++-Ausnahme: _com_error an Speicherposition 0x0049ed0c..
Meine Klasse:
#pragma once #include <d3d10.h> #include <d3dx10.h> #pragma comment (lib, "d3d10.lib") #pragma comment (lib, "d3dx10.lib") class cDXGraphics { private: ID3D10Device* pD3DDevice; ID3D10Texture2D* pBackBuffer; DXGI_SWAP_CHAIN_DESC swapDesc; ID3D10RenderTargetView* pRenderTargetView; IDXGISwapChain* pSwapChain; D3D10_VIEWPORT vp; public: cDXGraphics(void); ~cDXGraphics(void); bool InitD3D(HWND hWnd, unsigned int resX, unsigned int resY, unsigned int antiAliasing, bool windowMode); ID3D10Device* GetPointerToDevice() { return pD3DDevice; } IDXGISwapChain* GetPointerToSwapChain() { return pSwapChain; } ID3D10RenderTargetView* GetPointerToRenderTargetView() { return pRenderTargetView; } };
#include "cDXGraphics.h" cDXGraphics::cDXGraphics(void) { pD3DDevice = NULL; pBackBuffer = NULL; pRenderTargetView = NULL; pSwapChain = NULL; } cDXGraphics::~cDXGraphics(void) { pRenderTargetView->Release(); pBackBuffer->Release(); pSwapChain->Release(); pD3DDevice->Release(); } //this function initializes and prepares Direct3D for use bool cDXGraphics::InitD3D(HWND hWnd, unsigned int resX, unsigned int resY, unsigned int antiAliasing, bool windowMode) { // Structure to hold the creation parameters for the device ZeroMemory(&swapDesc, sizeof(swapDesc)); // Only want one back buffer swapDesc.BufferCount = 1; // Width and height of the back buffer swapDesc.BufferDesc.Width = resX; swapDesc.BufferDesc.Height = resY; // Standard 32bit surface type swapDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // 60hz refresh rate swapDesc.BufferDesc.RefreshRate.Numerator = 60; swapDesc.BufferDesc.RefreshRate.Denominator = 1; swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // Connect it to our main window swapDesc.OutputWindow = hWnd; // No multisampling swapDesc.SampleDesc.Count = antiAliasing; swapDesc.SampleDesc.Quality = 0; // Windowed mode swapDesc.Windowed = windowMode; // Create the device using hardware acceleration HRESULT hr = D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, D3D10_CREATE_DEVICE_DEBUG, D3D10_SDK_VERSION, &swapDesc, &pSwapChain, &pD3DDevice); if(FAILED(hr)) { MessageBox(NULL, "Failed to create device and swap chain.", "Error", MB_OK); return false; } // Create a render target view if( FAILED( pSwapChain->GetBuffer( 0, __uuidof( ID3D10Texture2D ), (LPVOID*)&pBackBuffer ) ) ) return false; hr = pD3DDevice->CreateRenderTargetView( pBackBuffer, NULL, &pRenderTargetView ); pBackBuffer->Release(); if( FAILED( hr ) ) { MessageBox(NULL, "Failed to create render target view.", "Error", MB_OK); return false; } pD3DDevice->OMSetRenderTargets( 1, &pRenderTargetView, NULL ); // initialize the viewport vp.Width = resX; vp.Height = resY; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.TopLeftX = 0; vp.TopLeftY = 0; pD3DDevice->RSSetViewports( 1, &vp ); return true; }
Weiß jemand Rat?
-
Steht eh in der Fehlermeldung: "The Dimensions are invalid."
Deine Höhe und Breite sind offenbar Quatsch. Debugg halt mal und schau wo die komischen Werte herkommen (schaut irgendwie aus als wären die nicht initialisiert).
Abgesehen davon: Hast du einen spziellen Grund warum du D3D10 verwenden musst? Ansonsten würd ich nämlich schwer dazu raten gleich das aktuelle D3D11 zu verwenden, das hat gegenüber D3D10 nämlich nur Vorteile und keinen einzigen Nachteil
-
Ah, ich hab den Wald vor lauter Bäumen nicht mehr gesehen. Dachte, die Werte werden korrekt übergeben, war dann aber doch nicht so, danke.
Der einzige Grund, warum ich DX10 benutze ist, weil ich ein Buch dazu habe.