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
Prevent deadlock when calling SetWindowPos from another thread #14306
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please drop changes that I commented, because Kodi expects old behavior in these places. I think it will not cause an issue, but I don't want to risk at this stage of development v18.
@@ -401,7 +401,7 @@ void CWinSystemWin32::AdjustWindow(bool forceResize) | |||
rc.top, | |||
rc.right - rc.left, | |||
rc.bottom - rc.top, | |||
SWP_SHOWWINDOW | SWP_DRAWFRAME | |||
SWP_SHOWWINDOW | SWP_DRAWFRAME | SWP_ASYNCWINDOWPOS |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -586,7 +586,7 @@ bool CWinSystemWin32::DPIChanged(WORD dpi, RECT windowRect) const | |||
resizeRect.top, | |||
resizeRect.right - resizeRect.left, | |||
resizeRect.bottom - resizeRect.top, | |||
SWP_NOZORDER | SWP_NOACTIVATE); | |||
SWP_NOZORDER | SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -1122,7 +1122,7 @@ void CWinSystemWin32::NotifyAppFocusChange(bool bGaining) | |||
ReleaseBackBuffer(); | |||
|
|||
if (bGaining) | |||
SetWindowPos(m_hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREDRAW); | |||
SetWindowPos(m_hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREDRAW | SWP_ASYNCWINDOWPOS); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -1132,7 +1132,7 @@ void CWinSystemWin32::NotifyAppFocusChange(bool bGaining) | |||
SetDeviceFullScreen(bGaining, res); | |||
|
|||
if (!bGaining) | |||
SetWindowPos(m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREDRAW); | |||
SetWindowPos(m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREDRAW | SWP_ASYNCWINDOWPOS); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
after some thoughts I concluded that you fixed consequence but not a root reason. CExternalPlayer shouldn't change window not from main thread. So in my opinion acceptable solution is sending a message/event to the main thread to change window. @FernetMenta what do you think? |
Right, SetWindowPos is Windows API function and must only be called by windowing component.
I am not sure if this is Windows only or something generic. |
You are right but if anybody uses SetWindowPos from another thread again!? |
won't happen if g_hWnd gets eliminated. |
nobody except windowing shouldn't use SetWindowPos. Using SetWindowPos from ExternalPlayer is bad. Fernet is right
application events are processed from main thread only. |
@afedchin @FernetMenta when ill do the changes to the PR and leave the async flag in exernal player (which is a quick fix), do you merge it? We than can create an ticket for removing the g_hWnd variable. What do you think? |
I never do such quick hacks but I leave the decision to @afedchin |
… (flag SWP_ASYNCWINDOWPOS)
38bc8bb
to
8336dfb
Compare
I'll removed the flag from other code playces and just leave it there which belongs to ExternalPlayer. We can make a ticket which describes the issue and thats the best way is to eleminate the g_hWnd variable. Thanks |
If it is not fixed properly now, nobody will care afterwards. We have
enough tickets open already.
popy2k14 <notifications@github.com> schrieb am Sa., 18. Aug. 2018, 13:18:
… I'll removed the flag from other code playces and just leave it there
which belongs to ExternalPlayer.
@afedchin <https://github.com/afedchin> Please, whats your decision?
Would be nice if you merge this because some of use using ExternalPlayer
currently :-)
We can make a ticket which describes the issue and thats the best way is
to eleminate the g_hWnd variable.
Thanks
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#14306 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABCfHamF2CRkGGNyqPGF5idm2LgOUmBeks5uR_gRgaJpZM4WAVvl>
.
|
Yeah. but eliminating the variable will not be that easy. \xbmc\xbmc\cores\AudioEngine\Sinks\AESinkDirectSound.cpp(163): HWND tmp_hWnd = g_hWnd == nullptr ? GetDesktopWindow() : g_hWnd; As an example in the ZeroconfBrowserMDNS.cpp the WSAAsyncSelect needs an hwnd where the event gets passed after select is ok, so there the correct hwnd is needed for this to work. |
If current fix resolves the issue, I can aprove it.
It's right way, you just doesn't see how to resolve it. |
The current fix resolves the main issue, please aprove it. |
no need. I've added this to my todo list |
thanks. merged |
Thanks! |
flag SWP_ASYNCWINDOWPOS, see https://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
Description
When SetWindowPos is called from another thread with the main gui HWND, kodi freezes!
This was the case on ExternalPlayer.cpp, see ticket: https://trac.kodi.tv/ticket/17988
My PR adds the SWP_ASYNCWINDOWPOS flag on all SetWindowPos.
So the risk of ever running into the same problem, when calling ->Show() is low.
Motivation and Context
Kodi freezes when external player is active and STOP is pressed on keyboard or received, json, remote...
How Has This Been Tested?
On my dev machine, the issue is reproduce able like described in the ticket.
After the PR, issue is gone for me.
Types of change
Checklist: