DX11 gives me a invalid window warning

Started by
0 comments, last by Nanook 11 years, 5 months ago
I'm getting a warning when I'm creating my swap chain and nothing is drawn.. It was working, I don't think I've changed anything in the code below, but what else could it be?

DXGI WARNING: IDXGIFactory::CreateSwapChain: DXGI_SWAP_CHAIN_DESC.OutputWindow is not a valid window handle. [ MISCELLANEOUS WARNING #65: ]

CreateSwapChain code:

void TE::Context::APIContext::CreateSwapChain(Platform::PlatformWindow& platformWindow)
{
HRESULT hr = S_OK;
unsigned createDeviceFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
};
unsigned numDriverTypes = ARRAYSIZE( driverTypes );
D3D_FEATURE_LEVEL featureLevels[] =
{
//D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
};
unsigned numFeatureLevels = ARRAYSIZE( featureLevels );
D3D_DRIVER_TYPE driverType;
for( U32 driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
{
driverType = driverTypes[driverTypeIndex];

ID3D11Device* device;
ID3D11DeviceContext* deviceContext;
hr = D3D11CreateDevice(NULL,
driverType,
nullptr,
createDeviceFlags,
featureLevels,
numFeatureLevels,
D3D11_SDK_VERSION,
&device,
&m_d3dFeatureLevel,
&deviceContext);
if( SUCCEEDED( hr ) )
{
m_d3dDevice = static_cast<ID3D11Device1*>(device);
m_d3dDeviceContext = static_cast<ID3D11DeviceContext1*>(deviceContext);
break;
}
}
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
swapChainDesc.Stereo = false;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
swapChainDesc.Flags = 0;
// Use automatic sizing.
swapChainDesc.Width = 0;
swapChainDesc.Height = 0;
swapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.BufferCount = 2;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
IDXGIDevice2* dxgiDevice;
m_d3dDevice->QueryInterface(__uuidof(IDXGIDevice2), (void **)&dxgiDevice);
dxgiDevice->SetMaximumFrameLatency(1);
IDXGIAdapter* dxgiAdapter;
dxgiDevice->GetAdapter(&dxgiAdapter);
IDXGIFactory2* dxgiFactory;
dxgiAdapter->GetParent(IID_PPV_ARGS(&dxgiFactory));

hr = dxgiFactory->CreateSwapChainForHwnd(m_d3dDevice,
platformWindow.GetHWND(),
&swapChainDesc,
nullptr,
nullptr,
&m_d3dSwapChain);
if( FAILED( hr ) )
//LOG FATAL ERROR
exit(0);
}


Create window code:

void TE::Platform::PlatformWindow::Initialize()
{
if (!m_externalWindow)
{
m_hInstance = (HINSTANCE)GetWindowLong(NULL,GWL_HINSTANCE);
WNDCLASSEX wcex = {};
wcex.cbSize = sizeof( WNDCLASSEX );
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = m_hInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
wcex.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1 );
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "TEngine";
wcex.hIconSm = NULL;
if(!RegisterClassEx (&wcex))
//LOG FATAL ERROR
exit(0);
I32 posx = 0;
I32 posy = 0;
I32 width = m_width;
I32 height = m_height;
RECT rc =
{
posx, posy,
posx + width,
posy + height
};
AdjustWindowRect(&rc, m_dwWindowStyle, false);
m_hWnd = CreateWindow(
m_windowName.c_str(),
m_windowName.c_str(),
m_dwWindowStyle | WS_CAPTION | WS_SYSMENU, //| WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
//WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
rc.right - rc.left, rc.bottom - rc.top,
NULL, NULL, m_hInstance, NULL );
if (!m_hWnd)
//LOG FATAL ERROR
exit(0);
s_hwndPlatformWindowMap.insert(std::make_pair(m_hWnd, this));
ShowWindow(m_hWnd, SW_SHOWNORMAL);
SetFocus(m_hWnd);
}
m_hdc = GetDC(m_hWnd);
}
Advertisement
Never mind.. I was using a copy instead of a reference of the PlatformWindow and the HWND wasn't copied properly..

This topic is closed to new replies.

Advertisement