Skip to content

Commit

Permalink
Merge pull request xbmc#25025 from thexai/fix-Xbox-crash
Browse files Browse the repository at this point in the history
[Xbox] Fix crash when DisplayInformation it's called from other thread
  • Loading branch information
thexai authored Apr 21, 2024
2 parents c7520ee + 2f7c5c6 commit bcf678b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
9 changes: 8 additions & 1 deletion xbmc/windowing/win10/WinSystemWin10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,14 @@ float CWinSystemWin10::GetGuiSdrPeakLuminance() const
*/
bool CWinSystemWin10::HasSystemSdrPeakLuminance()
{
return CWIN32Util::GetSystemSdrWhiteLevel(std::wstring(), nullptr);
if (m_uiThreadId == GetCurrentThreadId())
{
const bool hasSystemSdrPeakLum = CWIN32Util::GetSystemSdrWhiteLevel(std::wstring(), nullptr);
m_cachedHasSystemSdrPeakLum = hasSystemSdrPeakLum;
return hasSystemSdrPeakLum;
}

return m_cachedHasSystemSdrPeakLum;
}

/*!
Expand Down
4 changes: 4 additions & 0 deletions xbmc/windowing/win10/WinSystemWin10.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ class CWinSystemWin10 : public CWinSystemBase

bool m_validSystemSdrPeakLuminance{false};
float m_systemSdrPeakLuminance{.0f};

DWORD m_uiThreadId{0};
HDR_STATUS m_cachedHdrStatus{HDR_STATUS::HDR_UNSUPPORTED};
bool m_cachedHasSystemSdrPeakLum{false};
};

#pragma pack(pop)
Expand Down
17 changes: 16 additions & 1 deletion xbmc/windowing/win10/WinSystemWin10DX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ bool CWinSystemWin10DX::CreateNewWindow(const std::string& name, bool fullScreen
m_deviceResources = DX::DeviceResources::Get();
m_deviceResources->SetWindow(m_coreWindow);

// saves threadId of current thread (UI thread)
m_uiThreadId = GetCurrentThreadId();

// calls these methods to make sure cached values are properly initialized
// and can be used later when called from other thread
IsHDRDisplay();
HasSystemSdrPeakLuminance();

if (CWinSystemWin10::CreateNewWindow(name, fullScreen, res) && m_deviceResources->HasValidDevice())
{
CGenericTouchInputHandler::GetInstance().RegisterHandler(&CGenericTouchActionHandler::GetInstance());
Expand Down Expand Up @@ -166,7 +174,14 @@ void CWinSystemWin10DX::InitHooks(IDXGIOutput* pOutput)

bool CWinSystemWin10DX::IsHDRDisplay()
{
return (CWIN32Util::GetWindowsHDRStatus() != HDR_STATUS::HDR_UNSUPPORTED);
if (m_uiThreadId == GetCurrentThreadId())
{
const HDR_STATUS hdrStatus = CWIN32Util::GetWindowsHDRStatus();
m_cachedHdrStatus = hdrStatus;
return (hdrStatus != HDR_STATUS::HDR_UNSUPPORTED);
}

return (m_cachedHdrStatus != HDR_STATUS::HDR_UNSUPPORTED);
}

HDR_STATUS CWinSystemWin10DX::GetOSHDRStatus()
Expand Down

0 comments on commit bcf678b

Please sign in to comment.