From 97b1c09b59cac4656b31e87981f659d9743e2e70 Mon Sep 17 00:00:00 2001 From: Elisha Riedlinger Date: Tue, 12 Sep 2023 18:50:33 -0700 Subject: [PATCH] Delay device creation and fix device size --- Dllmain/BuildNo.rc | 2 +- ddraw/IDirectDrawSurfaceX.h | 4 +++- ddraw/IDirectDrawX.cpp | 16 ++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Dllmain/BuildNo.rc b/Dllmain/BuildNo.rc index af710982..db13208f 100644 --- a/Dllmain/BuildNo.rc +++ b/Dllmain/BuildNo.rc @@ -1 +1 @@ -#define BUILD_NUMBER 6812 +#define BUILD_NUMBER 6813 diff --git a/ddraw/IDirectDrawSurfaceX.h b/ddraw/IDirectDrawSurfaceX.h index 01a47714..0a1ff690 100644 --- a/ddraw/IDirectDrawSurfaceX.h +++ b/ddraw/IDirectDrawSurfaceX.h @@ -422,7 +422,9 @@ class m_IDirectDrawSurfaceX : public IUnknown, public AddressLookupTableDdrawObj } inline bool GetSurfaceSetSize(DWORD& Width, DWORD& Height) { - if ((ResetDisplayFlags & (DDSD_WIDTH | DDSD_HEIGHT)) == 0 && surfaceDesc2.dwWidth && surfaceDesc2.dwHeight) + if ((surfaceDesc2.dwFlags & (DDSD_WIDTH | DDSD_HEIGHT)) == (DDSD_WIDTH | DDSD_HEIGHT) && + (ResetDisplayFlags & (DDSD_WIDTH | DDSD_HEIGHT)) == 0 && + surfaceDesc2.dwWidth && surfaceDesc2.dwHeight) { Width = surfaceDesc2.dwWidth; Height = surfaceDesc2.dwHeight; diff --git a/ddraw/IDirectDrawX.cpp b/ddraw/IDirectDrawX.cpp index 172b2b78..fc703ded 100644 --- a/ddraw/IDirectDrawX.cpp +++ b/ddraw/IDirectDrawX.cpp @@ -640,8 +640,9 @@ HRESULT m_IDirectDrawX::CreateSurface2(LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRE // Get present parameters if (Desc2.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) { - Logging::LogDebug() << __FUNCTION__ << " Primary surface " << Desc2.dwWidth << "x" << Desc2.dwHeight << " ddsCaps: " << Logging::hex(Desc2.ddsCaps.dwCaps) << " " << - Logging::hex(Desc2.ddsCaps.dwCaps2) << " " << LOWORD(Desc2.ddsCaps.dwVolumeDepth); + Logging::Log() << __FUNCTION__ << " Primary surface " << Desc2.dwWidth << "x" << Desc2.dwHeight << + " dwFlags: " << Logging::hex(Desc2.dwFlags) << + " ddsCaps: " << Logging::hex(Desc2.ddsCaps.dwCaps) << ", " << Logging::hex(Desc2.ddsCaps.dwCaps2) << ", " << LOWORD(Desc2.ddsCaps.dwVolumeDepth); // Anti-aliasing if (!Config.AntiAliasing) @@ -1631,7 +1632,7 @@ HRESULT m_IDirectDrawX::SetCooperativeLevel(HWND hWnd, DWORD dwFlags, DWORD Dire Device.NoWindowChanges = ((dwFlags & DDSCL_NOWINDOWCHANGES) != 0); // Reset if mode was changed - if (LastExclusiveMode != ExclusiveMode || LasthWnd != DisplayMode.hWnd || LastFPUPreserve != Device.FPUPreserve || LastNoWindowChanges != Device.NoWindowChanges) + if (d3d9Device && (LastExclusiveMode != ExclusiveMode || LasthWnd != DisplayMode.hWnd || LastFPUPreserve != Device.FPUPreserve || LastNoWindowChanges != Device.NoWindowChanges)) { CreateD3D9Device(); } @@ -2761,8 +2762,8 @@ HRESULT m_IDirectDrawX::CreateD3D9Device() } // Get width and height - DWORD BackBufferWidth = Exclusive.Width; - DWORD BackBufferHeight = Exclusive.Height; + DWORD BackBufferWidth = Device.Width; + DWORD BackBufferHeight = Device.Height; if (!BackBufferWidth || !BackBufferHeight) { if (Direct3DSurface && Direct3DSurface->GetSurfaceSetSize(BackBufferWidth, BackBufferHeight)) @@ -2783,7 +2784,10 @@ HRESULT m_IDirectDrawX::CreateD3D9Device() else { // Reset display to get proper screen size - ChangeDisplaySettingsEx(nullptr, nullptr, nullptr, CDS_RESET, nullptr); + if (d3d9Device && !LastWindowedMode) + { + ChangeDisplaySettingsEx(nullptr, nullptr, nullptr, CDS_RESET, nullptr); + } BackBufferWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN); BackBufferHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN); }