Skip to content

Commit

Permalink
Reenable exclusive on non-exclusive device release
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Jan 23, 2025
1 parent 8bcc2b6 commit a7624a6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 7451
#define BUILD_NUMBER 7452
24 changes: 19 additions & 5 deletions ddraw/IDirectDrawX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,6 @@ HRESULT m_IDirectDrawX::SetCooperativeLevel(HWND hWnd, DWORD dwFlags, DWORD Dire
}

DisplayMode.hWnd = hWnd;
DisplayMode.SetBy = this;

if (DisplayMode.hWnd && !DisplayMode.DC)
{
Expand All @@ -1778,6 +1777,7 @@ HRESULT m_IDirectDrawX::SetCooperativeLevel(HWND hWnd, DWORD dwFlags, DWORD Dire
}

// Set windowed mode
DisplayMode.SetBy = this;
Device.IsWindowed = (!ExclusiveMode || FullScreenWindowed || Config.EnableWindowMode);

// Set device flags
Expand Down Expand Up @@ -2641,6 +2641,22 @@ void m_IDirectDrawX::ReleaseInterface()
SetCriticalSection();
SetPTCriticalSection();

// Remove ddraw device from vector
DDrawVector.erase(std::remove(DDrawVector.begin(), DDrawVector.end(), this), DDrawVector.end());

// Re-enable exclusive mode once non-exclusive device is released
if (ExclusiveMode &&
Device.IsWindowed && FullScreenWindowed &&
DisplayMode.SetBy == this && DisplayMode.SetBy != Exclusive.SetBy &&
std::find(DDrawVector.begin(), DDrawVector.end(), Exclusive.SetBy) != DDrawVector.end())
{
DisplayMode.SetBy = Exclusive.SetBy;
Device.IsWindowed = false;
FullScreenWindowed = false;

CreateD9Device(__FUNCTION__);
}

// Clear SetBy handles
if (DisplayMode.SetBy == this)
{
Expand All @@ -2651,9 +2667,6 @@ void m_IDirectDrawX::ReleaseInterface()
Exclusive.SetBy = nullptr;
}

// Remove ddraw device from vector
DDrawVector.erase(std::remove(DDrawVector.begin(), DDrawVector.end(), this), DDrawVector.end());

// Release Direct3DDevice interfaces
if (D3DDeviceInterface)
{
Expand Down Expand Up @@ -2712,7 +2725,7 @@ void m_IDirectDrawX::ReleaseInterface()

ReleasePTCriticalSection();

if (DDrawVector.size() == 0)
if (DDrawVector.empty())
{
// Close present thread first
if (PresentThread.IsInitialized)
Expand Down Expand Up @@ -3383,6 +3396,7 @@ HRESULT m_IDirectDrawX::CreateD9Device(char* FunctionName)
// Reset display mode after release when display mode is already setup and there is a primary surface
if (presParams.Windowed && (FullScreenWindowed || (PrimarySurface && DisplayMode.Width == CurrentWidth && DisplayMode.Height == CurrentHeight)))
{
FullScreenWindowed = true;
Utils::SetDisplaySettings(hWnd, DisplayMode.Width, DisplayMode.Height);
}
}
Expand Down

0 comments on commit a7624a6

Please sign in to comment.