From 29092677ceadfcb66fe7ac35f6f40cd69caa729b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 4 May 2026 22:25:11 +0200 Subject: [PATCH] UWP fixes after Gemini code review... --- UWP/App.cpp | 6 ++++-- UWP/PPSSPP_UWPMain.cpp | 18 +++++++++++++++--- UWP/XAudioSoundStream.cpp | 23 ++++++++++++++++------- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/UWP/App.cpp b/UWP/App.cpp index ef75269702..f48c5d097e 100644 --- a/UWP/App.cpp +++ b/UWP/App.cpp @@ -282,8 +282,10 @@ void App::OnSuspending(const IInspectable& sender, const SuspendingEventArgs& ar auto app = this; std::thread([app, deferral]() { - g_Config.Save("App::OnSuspending"); - app->m_deviceResources->Trim(); + try { + g_Config.Save("App::OnSuspending"); + app->m_deviceResources->Trim(); + } catch (...) {} deferral.Complete(); }).detach(); } diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index a89ee1f48c..838fa9e367 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -328,8 +328,14 @@ bool IsMobile() { } void GetVersionInfo(uint32_t& major, uint32_t& minor, uint32_t& build, uint32_t& revision) { + major = minor = build = revision = 0; winrt::hstring deviceFamilyVersion = winrt::Windows::System::Profile::AnalyticsInfo::VersionInfo().DeviceFamilyVersion(); - uint64_t version = std::stoull(std::wstring(deviceFamilyVersion)); + uint64_t version = 0; + try { + version = std::stoull(std::wstring(deviceFamilyVersion)); + } catch (...) { + return; + } major = static_cast((version & 0xFFFF000000000000L) >> 48); minor = static_cast((version & 0x0000FFFF00000000L) >> 32); @@ -432,6 +438,7 @@ int64_t System_GetPropertyInt(SystemProperty prop) { if (corewindow) { return (int)corewindow.Bounds().Width; } + return -1; } case SYSPROP_DISPLAY_YRES: { @@ -439,6 +446,7 @@ int64_t System_GetPropertyInt(SystemProperty prop) { if (corewindow) { return (int)corewindow.Bounds().Height; } + return -1; } default: return -1; @@ -651,8 +659,12 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string } void System_LaunchUrl(LaunchUrlType urlType, std::string_view url) { - auto uri = winrt::Windows::Foundation::Uri(ToHString(url)); - winrt::Windows::System::Launcher::LaunchUriAsync(uri); + try { + auto uri = winrt::Windows::Foundation::Uri(ToHString(url)); + winrt::Windows::System::Launcher::LaunchUriAsync(uri); + } catch (const winrt::hresult_error &e) { + ERROR_LOG(Log::System, "System_LaunchUrl: invalid URI: %s", winrt::to_string(e.message()).c_str()); + } } void System_Vibrate(int length_ms) { diff --git a/UWP/XAudioSoundStream.cpp b/UWP/XAudioSoundStream.cpp index 253543e96e..8852ab3af8 100644 --- a/UWP/XAudioSoundStream.cpp +++ b/UWP/XAudioSoundStream.cpp @@ -11,8 +11,6 @@ #include "Common/Audio/AudioBackend.h" #include "XAudioSoundStream.h" -const size_t BUFSIZE = 32 * 1024; - class XAudioBackend : public AudioBackend { public: XAudioBackend(); @@ -45,7 +43,7 @@ private: WAVEFORMATEX format_; - int sampleRate_ = 44100; + int sampleRate_ = 48000; int periodFrames_ = 0; enum { @@ -62,9 +60,6 @@ private: std::atomic running_{}; }; -// TODO: Get rid of this -static XAudioBackend *g_dsound; - XAudioBackend::XAudioBackend() { format_.wFormatTag = WAVE_FORMAT_IEEE_FLOAT; format_.nChannels = channels; @@ -85,10 +80,18 @@ void XAudioBackend::Stop() { thread_.join(); } + if (sourceVoice_) { + sourceVoice_->Stop(0, XAUDIO2_COMMIT_NOW); + sourceVoice_->DestroyVoice(); + sourceVoice_ = nullptr; + } + if (masterVoice_) { + masterVoice_->DestroyVoice(); + masterVoice_ = nullptr; + } if (xaudioDevice) { xaudioDevice->Release(); xaudioDevice = nullptr; - sourceVoice_ = nullptr; } } @@ -114,6 +117,8 @@ bool XAudioBackend::InitOutputDevice(std::string_view uniqueId, LatencyMode late } if FAILED(xaudioDevice->CreateSourceVoice(&sourceVoice_, &format_, 0, 1.0, nullptr, nullptr, nullptr)) { + masterVoice_->DestroyVoice(); + masterVoice_ = nullptr; xaudioDevice->Release(); xaudioDevice = nullptr; return false; @@ -124,6 +129,10 @@ bool XAudioBackend::InitOutputDevice(std::string_view uniqueId, LatencyMode late cursor_ = 0; if FAILED(sourceVoice_->Start(0, XAUDIO2_COMMIT_NOW)) { + sourceVoice_->DestroyVoice(); + sourceVoice_ = nullptr; + masterVoice_->DestroyVoice(); + masterVoice_ = nullptr; xaudioDevice->Release(); xaudioDevice = nullptr; return false;