diff --git a/Matchstick/src/core/MGDFApp.cpp b/Matchstick/src/core/MGDFApp.cpp index 8bdeed4..2600a81 100644 --- a/Matchstick/src/core/MGDFApp.cpp +++ b/Matchstick/src/core/MGDFApp.cpp @@ -128,8 +128,12 @@ MGDFFullScreenDesc MGDFApp::OnResetSwapChain( } void MGDFApp::OnSwapChainCreated(ComObject &swapchain) { - swapchain.As()->SetMaximumFrameLatency( - _settings->GetMaxFrameLatency()); + MGDFFullScreenDesc desc; + _settings->GetFullscreen(&desc); + if (!desc.ExclusiveMode) { + swapchain.As()->SetMaximumFrameLatency( + _settings->GetMaxFrameLatency()); + } } void MGDFApp::OnResize(UINT32 width, UINT32 height) { diff --git a/Matchstick/src/core/MGDFD3DAppFramework.cpp b/Matchstick/src/core/MGDFD3DAppFramework.cpp index aac6d9e..982726c 100644 --- a/Matchstick/src/core/MGDFD3DAppFramework.cpp +++ b/Matchstick/src/core/MGDFD3DAppFramework.cpp @@ -321,9 +321,13 @@ void D3DAppFramework::UninitD3D() { _immediateContext->Flush(); } - if (_swapChain) { - // d3d has to be in windowed mode to cleanup correctly - _swapChain->SetFullscreenState(false, nullptr); + if (_swapChain && _currentFullScreen.ExclusiveMode) { + BOOL fullscreen = false; + if (FAILED(_swapChain->GetFullscreenState(&fullscreen, nullptr)) && + fullscreen) { + // d3d has to be in windowed mode to cleanup correctly + _swapChain->SetFullscreenState(false, nullptr); + } } _backBuffer.Clear(); @@ -540,20 +544,18 @@ INT32 D3DAppFramework::Run() { const MGDFFullScreenDesc newFullScreen = OnResetSwapChain(_swapDesc, _fullscreenSwapDesc, windowSize); - if (_currentFullScreen.ExclusiveMode) { + if (_swapChain && _currentFullScreen.ExclusiveMode) { // clean up the old swap chain, then recreate it with the new // settings BOOL fullscreen = false; - if (_swapChain) { - if (FAILED(_swapChain->GetFullscreenState(&fullscreen, - target.Assign()))) { - FATALERROR(this, "GetFullscreenState failed"); - } - if (fullscreen) { - // d3d has to be in windowed mode to cleanup correctly - if (FAILED(_swapChain->SetFullscreenState(false, nullptr))) { - FATALERROR(this, "SetFullscreenState failed"); - } + if (FAILED(_swapChain->GetFullscreenState(&fullscreen, + target.Assign()))) { + FATALERROR(this, "GetFullscreenState failed"); + } + if (fullscreen) { + // d3d has to be in windowed mode to cleanup correctly + if (FAILED(_swapChain->SetFullscreenState(false, nullptr))) { + FATALERROR(this, "SetFullscreenState failed"); } } } diff --git a/Matchstick/src/core/core.impl/MGDFRenderSettingsManagerImpl.cpp b/Matchstick/src/core/core.impl/MGDFRenderSettingsManagerImpl.cpp index 66128d9..2cf2157 100644 --- a/Matchstick/src/core/core.impl/MGDFRenderSettingsManagerImpl.cpp +++ b/Matchstick/src/core/core.impl/MGDFRenderSettingsManagerImpl.cpp @@ -344,8 +344,10 @@ void RenderSettingsManager::OnResetSwapChain( desc.BufferCount = 2; desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; - desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH | - DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT; + desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + if (!_fullScreen.ExclusiveMode) { + desc.Flags |= DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT; + } desc.Format = BACKBUFFER_FORMAT; desc.SampleDesc.Count = _backBufferMultiSampleLevel; desc.SampleDesc.Quality = diff --git a/Matchstick/src/core/main.cpp b/Matchstick/src/core/main.cpp index 919a2bf..1201a72 100644 --- a/Matchstick/src/core/main.cpp +++ b/Matchstick/src/core/main.cpp @@ -43,9 +43,11 @@ D3DAPP_WNDPROC(MGDFAppWndProc, _application) INT32 WINAPI WinMain(_In_ HINSTANCE const hInstance, _In_opt_ HINSTANCE const hPreviousInstance, _In_ LPSTR const lpCmdLine, _In_ INT32 const nCmdShow) { - (void)nCmdShow; - (void)lpCmdLine; - (void)hPreviousInstance; + std::ignore = nCmdShow; + std::ignore = lpCmdLine; + std::ignore = hPreviousInstance; + const HRESULT comHr = CoInitialize(NULL); + // Catch memory leaks #if defined(_DEBUG) _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); @@ -90,6 +92,10 @@ INT32 WINAPI WinMain(_In_ HINSTANCE const hInstance, timeEndPeriod(1); + if (SUCCEEDED(comHr)) { + CoUninitialize(); + } + LOG("shut down successfully", MGDF_LOG_LOW); return 0; }