From 25e2c5195c4d9fea712c1d5977c56923cfc8258a Mon Sep 17 00:00:00 2001 From: DFlame Blazer Date: Sat, 15 Jun 2019 08:51:08 -0500 Subject: [PATCH 1/2] Crash fixes for window size and camera R --- hw3d/Camera.cpp | 3 ++- hw3d/Graphics.cpp | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/hw3d/Camera.cpp b/hw3d/Camera.cpp index 5fb6b91..0a5f0b0 100644 --- a/hw3d/Camera.cpp +++ b/hw3d/Camera.cpp @@ -22,7 +22,7 @@ void Camera::SpawnControlWindow() noexcept if( ImGui::Begin( "Camera" ) ) { ImGui::Text( "Position" ); - ImGui::SliderFloat( "R",&r,0.0f,80.0f,"%.1f" ); + ImGui::SliderFloat( "R",&r, FLT_EPSILON,80.0f,"%.1f" ); ImGui::SliderAngle( "Theta",&theta,-180.0f,180.0f ); ImGui::SliderAngle( "Phi",&phi,-89.0f,89.0f ); ImGui::Text( "Orientation" ); @@ -35,6 +35,7 @@ void Camera::SpawnControlWindow() noexcept } } ImGui::End(); + if( r <= 0 ) r = FLT_EPSILON; } void Camera::Reset() noexcept diff --git a/hw3d/Graphics.cpp b/hw3d/Graphics.cpp index fd27324..ac3c559 100644 --- a/hw3d/Graphics.cpp +++ b/hw3d/Graphics.cpp @@ -17,6 +17,9 @@ namespace dx = DirectX; Graphics::Graphics( HWND hWnd ) { + RECT rcTemp; + GetWindowRect( hWnd, &rcTemp ); + DXGI_SWAP_CHAIN_DESC sd = {}; sd.BufferDesc.Width = 0; sd.BufferDesc.Height = 0; @@ -77,8 +80,8 @@ Graphics::Graphics( HWND hWnd ) // create depth stensil texture wrl::ComPtr pDepthStencil; D3D11_TEXTURE2D_DESC descDepth = {}; - descDepth.Width = 800u; - descDepth.Height = 600u; + descDepth.Width = rcTemp.right; + descDepth.Height = rcTemp.bottom; descDepth.MipLevels = 1u; descDepth.ArraySize = 1u; descDepth.Format = DXGI_FORMAT_D32_FLOAT; @@ -102,8 +105,8 @@ Graphics::Graphics( HWND hWnd ) // configure viewport D3D11_VIEWPORT vp; - vp.Width = 800.0f; - vp.Height = 600.0f; + vp.Width = rcTemp.right; + vp.Height = rcTemp.bottom; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.TopLeftX = 0.0f; From b64efa76a6f0b8b37d523fdd8ee41861f17994f7 Mon Sep 17 00:00:00 2001 From: DFlame Blazer Date: Sat, 15 Jun 2019 10:14:12 -0500 Subject: [PATCH 2/2] GetWindowRect exception handling --- hw3d/Graphics.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw3d/Graphics.cpp b/hw3d/Graphics.cpp index ac3c559..190324a 100644 --- a/hw3d/Graphics.cpp +++ b/hw3d/Graphics.cpp @@ -17,8 +17,13 @@ namespace dx = DirectX; Graphics::Graphics( HWND hWnd ) { + // for checking results of d3d functions + HRESULT hr; + RECT rcTemp; - GetWindowRect( hWnd, &rcTemp ); + if( !GetWindowRect( hWnd, &rcTemp ) ) { + GFX_EXCEPT( __HRESULT_FROM_WIN32( GetLastError() ) ); + } DXGI_SWAP_CHAIN_DESC sd = {}; sd.BufferDesc.Width = 0; @@ -42,9 +47,6 @@ Graphics::Graphics( HWND hWnd ) swapCreateFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif - // for checking results of d3d functions - HRESULT hr; - // create device and front/back buffers, and swap chain and rendering context GFX_THROW_INFO( D3D11CreateDeviceAndSwapChain( nullptr,