diff --git a/DDrawCompat/DDraw/RealPrimarySurface.cpp b/DDrawCompat/DDraw/RealPrimarySurface.cpp index d244837..851445c 100644 --- a/DDrawCompat/DDraw/RealPrimarySurface.cpp +++ b/DDrawCompat/DDraw/RealPrimarySurface.cpp @@ -170,9 +170,9 @@ namespace CALL_ORIG_PROC(DirectDrawEnumerateExA)(createDefaultPrimaryEnum, &dm.deviceName, DDENUM_ATTACHEDSECONDARYDEVICES); } - CompatPtr createWindowedBackBuffer(DWORD width, DWORD height) + CompatPtr createWindowedBackBuffer(DDraw::TagSurface& tagSurface, DWORD width, DWORD height) { - auto resource = DDraw::DirectDrawSurface::getDriverResourceHandle(*g_tagSurface->getDDS()); + auto resource = DDraw::DirectDrawSurface::getDriverResourceHandle(*tagSurface.getDDS()); if (!resource) { LOG_INFO << "ERROR: createWindowedBackBuffer: driver resource handle not found"; @@ -428,6 +428,7 @@ namespace DDraw { LOG_FUNC("RealPrimarySurface::create", &dd); DDraw::ScopedThreadLock lock; + auto prevMonitorRect = g_monitorRect; g_monitorRect = Win32::DisplayMode::getMonitorInfo( D3dDdi::KernelModeThunks::getAdapterInfo(*CompatPtr::from(&dd)).deviceName).rcMonitor; @@ -437,6 +438,7 @@ namespace DDraw desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE | DDSCAPS_COMPLEX | DDSCAPS_FLIP; desc.dwBackBufferCount = 2; + auto prevIsFullscreen = g_isFullscreen; g_isFullscreen = true; CompatPtr surface; HRESULT result = dd->CreateSurface(&dd, &desc, &surface.getRef(), nullptr); @@ -453,31 +455,34 @@ namespace DDraw if (FAILED(result)) { LOG_INFO << "ERROR: Failed to create the real primary surface: " << Compat::hex(result); - g_monitorRect = {}; + g_monitorRect = prevMonitorRect; + g_isFullscreen = prevIsFullscreen; return result; } auto ddLcl = DDraw::DirectDraw::getInt(dd.get()).lpLcl; - g_tagSurface = DDraw::TagSurface::get(ddLcl); - if (!g_tagSurface) + auto tagSurface = DDraw::TagSurface::get(ddLcl); + if (!tagSurface) { LOG_INFO << "ERROR: TagSurface not found"; - g_monitorRect = {}; + g_monitorRect = prevMonitorRect; + g_isFullscreen = prevIsFullscreen; return DDERR_GENERIC; } if (0 == desc.dwBackBufferCount) { - g_windowedBackBuffer = createWindowedBackBuffer( + g_windowedBackBuffer = createWindowedBackBuffer(*tagSurface, g_monitorRect.right - g_monitorRect.left, g_monitorRect.bottom - g_monitorRect.top).detach(); if (!g_windowedBackBuffer) { - g_monitorRect = {}; - g_tagSurface = nullptr; + g_monitorRect = prevMonitorRect; + g_isFullscreen = prevIsFullscreen; return DDERR_GENERIC; } } + g_tagSurface = tagSurface; g_frontBuffer = CompatPtr::from(surface.get()).detach(); g_frontBuffer->SetPrivateData(g_frontBuffer, IID_IReleaseNotifier, &g_releaseNotifier, sizeof(&g_releaseNotifier), DDSPD_IUNKNOWNPOINTER); diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp index 640cc6a..f1b9c35 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp @@ -90,23 +90,18 @@ namespace DDraw { LOG_FUNC("PrimarySurface::create", &dd, desc, surface); DDraw::RealPrimarySurface::destroyDefaultPrimary(); - if (g_primarySurface) - { - LOG_ONCE("Warning: suppressed an attempt to create multiple primary surfaces"); - return LOG_RESULT(DDERR_UNSUPPORTED); - } const auto& dm = DDraw::DirectDraw::getDisplayMode(*CompatPtr::from(&dd)); - g_deviceName = D3dDdi::KernelModeThunks::getAdapterInfo(*CompatPtr::from(&dd)).deviceName; - g_monitorRect = Win32::DisplayMode::getMonitorInfo(g_deviceName).rcMonitor; + auto deviceName = D3dDdi::KernelModeThunks::getAdapterInfo(*CompatPtr::from(&dd)).deviceName; + auto prevMonitorRect = g_monitorRect; + g_monitorRect = Win32::DisplayMode::getMonitorInfo(deviceName).rcMonitor; g_monitorRect.right = g_monitorRect.left + dm.dwWidth; g_monitorRect.bottom = g_monitorRect.top + dm.dwHeight; HRESULT result = RealPrimarySurface::create(*CompatPtr::from(&dd)); if (FAILED(result)) { - g_deviceName.clear(); - g_monitorRect = {}; + g_monitorRect = prevMonitorRect; return LOG_RESULT(result); } @@ -126,12 +121,12 @@ namespace DDraw if (FAILED(result)) { LOG_INFO << "ERROR: Failed to create the compat primary surface: " << Compat::hex(result); - g_deviceName.clear(); - g_monitorRect = {}; + g_monitorRect = prevMonitorRect; RealPrimarySurface::release(); return LOG_RESULT(result); } + g_deviceName = deviceName; g_origCaps = origCaps; g_deviceWindow = *DDraw::DirectDraw::getDeviceWindowPtr(dd.get()); g_gdiPrimarySurface = createGdiPrimarySurface(*CompatPtr::from(&dd)).detach();