Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualN.I.B.

Posted 27 November 2013 - 01:33 AM

That's the problem:

 

 


HWND hwnd = CreateWindowA("DX11BookWindowClass", "Blank Win32 Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance, NULL);

You use a local variable to store the HWND, but then when you call D3D11CreateDeviceAndSwapChain(), you use a global variable with the same name. Since the global variable was never set correctly and is still NULL, D3D11CreateDeviceAndSwapChain() fails. When you run it in debug mode, it shows the failure in the debug log.

Change the line above to:

// Initialize the GLOBAL hwnd
hwnd = CreateWindowA("DX11BookWindowClass", "Blank Win32 Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance, NULL); 

To avoid confusing global and local variables, you need a better naming convention. Specifically for HWND - you don't need it as global variable, as it's required only for initialization. Same goes for other variables. The only ones you want to keep as globals are the device and the swap-chain.


#1N.I.B.

Posted 27 November 2013 - 01:31 AM

That's the problem:


HWND hwnd = CreateWindowA("DX11BookWindowClass", "Blank Win32 Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance, NULL);

You use a local variable to store the HWND, but then when you call D3D11CreateDeviceAndSwapChain(), you use a global variable called 'hwnd', which was never set, so this call fails. When you run it in debug mode, it actually says that in the debug log.

Change the line above to:

// Initialize the GLOBAL hwnd
hwnd = CreateWindowA("DX11BookWindowClass", "Blank Win32 Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance, NULL); 

To avoid confusing global and local variables, you need a better naming convention. Specifically for HWND - you don't need it as global variable, as it's required only for initialization. Same goes for other variables. The only ones you want to keep as globals are the device and the swap-chain.


PARTNERS