Skip to content

Commit

Permalink
修复忘记释放某些 mutex (#938)
Browse files Browse the repository at this point in the history
* fix: 修复忘记释放某些 mutex

* fix: 修复模拟独占全屏错误
  • Loading branch information
Blinue authored Jun 5, 2024
1 parent 8028dcd commit 1f60b82
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Magpie.Core/ExclModeHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ wil::unique_mutex_nothrow ExclModeHelper::EnterExclMode() noexcept {
return exclModeMutex;
}

if (!wil::event_is_signaled(exclModeMutex.get())) {
if (!wil::handle_wait(exclModeMutex.get(), 0)) {
Logger::Get().Error("获取 __DDrawExclMode__ 失败");
exclModeMutex.reset();
return exclModeMutex;
Expand All @@ -39,11 +39,13 @@ wil::unique_mutex_nothrow ExclModeHelper::EnterExclMode() noexcept {
hr = SHQueryUserNotificationState(&state);
if (FAILED(hr)) {
Logger::Get().ComError("SHQueryUserNotificationState 失败", hr);
exclModeMutex.ReleaseMutex();
exclModeMutex.reset();
return exclModeMutex;
}
if (state != QUNS_RUNNING_D3D_FULL_SCREEN) {
Logger::Get().Error("模拟独占全屏失败");
exclModeMutex.ReleaseMutex();
exclModeMutex.reset();
return exclModeMutex;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Magpie.Core/ScalingWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,10 @@ LRESULT ScalingWindow::_MessageHandler(UINT msg, WPARAM wParam, LPARAM lParam) n
}
case WM_DESTROY:
{
_exclModeMutex.reset();
if (_exclModeMutex) {
_exclModeMutex.ReleaseMutex();
_exclModeMutex.reset();
}

_hwndDDF.reset();
_isDDFWindowShown = false;
Expand Down
4 changes: 3 additions & 1 deletion src/Updater/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ static bool WaitForMagpieToExit() noexcept {
{
wil::unique_mutex_nothrow hSingleInstanceMutex;
if (hSingleInstanceMutex.try_create(CommonSharedConstants::SINGLE_INSTANCE_MUTEX_NAME)) {
wil::handle_wait(hSingleInstanceMutex.get(), 10000);
if (wil::handle_wait(hSingleInstanceMutex.get(), 10000)) {
hSingleInstanceMutex.ReleaseMutex();
}
}
}

Expand Down

0 comments on commit 1f60b82

Please sign in to comment.