Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复忘记释放某些 mutex #938

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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