From 48ddebd82e1029876661010bd6c81f49c45f4182 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 25 Oct 2021 18:42:00 +1000 Subject: [PATCH] UWP: Fix possible crash on startup in SizeChanged --- src/duckstation-uwp/uwp_host_interface.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/duckstation-uwp/uwp_host_interface.cpp b/src/duckstation-uwp/uwp_host_interface.cpp index 41146ed22..147d2671d 100644 --- a/src/duckstation-uwp/uwp_host_interface.cpp +++ b/src/duckstation-uwp/uwp_host_interface.cpp @@ -145,8 +145,8 @@ bool UWPHostInterface::CreateDisplay(bool fullscreen) GAMING_DEVICE_MODEL_INFORMATION gdinfo = {}; if (SUCCEEDED(GetGamingDeviceModelInformation(&gdinfo)) && gdinfo.vendorId == GAMING_DEVICE_VENDOR_ID_MICROSOFT) { - Log_InfoPrintf("Overriding core window size %ux%u with HDMI size %ux%u", wi.surface_width, - wi.surface_height, hdmi_width, hdmi_height); + Log_InfoPrintf("Overriding core window size %ux%u with HDMI size %ux%u", wi.surface_width, wi.surface_height, + hdmi_width, hdmi_height); wi.surface_scale *= static_cast(hdmi_width) / static_cast(wi.surface_width); wi.surface_width = hdmi_width; wi.surface_height = hdmi_height; @@ -501,13 +501,17 @@ void UWPHostInterface::OnClosed(const IInspectable&, const winrt::Windows::UI::C void UWPHostInterface::OnSizeChanged(const IInspectable&, const winrt::Windows::UI::Core::WindowSizeChangedEventArgs& args) { - const auto size = args.Size(); - const s32 width = static_cast(size.Width * m_display->GetWindowScale()); - const s32 height = static_cast(size.Height * m_display->GetWindowScale()); if (IsEmulationThreadRunning()) { + const auto size = args.Size(); + const float width = size.Width; + const float height = size.Height; RunLater([this, width, height]() { - m_display->ResizeRenderWindow(width, height); + if (!m_display) + return; + + m_display->ResizeRenderWindow(static_cast(width * m_display->GetWindowScale()), + static_cast(height * m_display->GetWindowScale())); OnHostDisplayResized(); }); }