Skip to content

Commit

Permalink
Fixed some warnings due to not initializing COM on startup
Browse files Browse the repository at this point in the history
Fixed issues setting framewaitable on swapchains that were fullscreen exclusive
  • Loading branch information
mrsharpoblunto committed May 12, 2023
1 parent 91d6f6f commit d676377
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
8 changes: 6 additions & 2 deletions Matchstick/src/core/MGDFApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ MGDFFullScreenDesc MGDFApp::OnResetSwapChain(
}

void MGDFApp::OnSwapChainCreated(ComObject<IDXGISwapChain1> &swapchain) {
swapchain.As<IDXGISwapChain2>()->SetMaximumFrameLatency(
_settings->GetMaxFrameLatency());
MGDFFullScreenDesc desc;
_settings->GetFullscreen(&desc);
if (!desc.ExclusiveMode) {
swapchain.As<IDXGISwapChain2>()->SetMaximumFrameLatency(
_settings->GetMaxFrameLatency());
}
}

void MGDFApp::OnResize(UINT32 width, UINT32 height) {
Expand Down
30 changes: 16 additions & 14 deletions Matchstick/src/core/MGDFD3DAppFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
12 changes: 9 additions & 3 deletions Matchstick/src/core/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit d676377

Please sign in to comment.