diff --git a/Gems/Atom/Bootstrap/Code/Source/BootstrapSystemComponent.cpp b/Gems/Atom/Bootstrap/Code/Source/BootstrapSystemComponent.cpp index f7aaae5deb4d..78fa225b625d 100644 --- a/Gems/Atom/Bootstrap/Code/Source/BootstrapSystemComponent.cpp +++ b/Gems/Atom/Bootstrap/Code/Source/BootstrapSystemComponent.cpp @@ -268,6 +268,9 @@ namespace AZ Render::Bootstrap::DefaultWindowBus::Handler::BusConnect(); Render::Bootstrap::RequestBus::Handler::BusConnect(); + // Listen for application's window creation/destruction (e.g. window is created/destroyed on Android when suspending the app) + AzFramework::ApplicationLifecycleEvents::Bus::Handler::BusConnect(); + // delay one frame for Initialize which asset system is ready by then AZ::TickBus::QueueFunction( [this]() @@ -292,6 +295,7 @@ namespace AZ void BootstrapSystemComponent::Deactivate() { + AzFramework::ApplicationLifecycleEvents::Bus::Handler::BusDisconnect(); Render::Bootstrap::RequestBus::Handler::BusDisconnect(); Render::Bootstrap::DefaultWindowBus::Handler::BusDisconnect(); @@ -367,6 +371,25 @@ namespace AZ } } + void BootstrapSystemComponent::OnApplicationWindowCreated() + { + if (!m_nativeWindow) + { + auto projectTitle = AZ::Utils::GetProjectDisplayName(); + m_nativeWindow = AZStd::make_unique(projectTitle.c_str(), AzFramework::WindowGeometry(0, 0, r_width, r_height)); + AZ_Assert(m_nativeWindow, "Failed to create the game window\n"); + + m_nativeWindow->Activate(); + + OnWindowCreated(m_nativeWindow->GetWindowHandle()); + } + } + + void BootstrapSystemComponent::OnApplicationWindowDestroy() + { + m_nativeWindow = nullptr; + } + void BootstrapSystemComponent::CreateViewportContext() { RHI::Device* device = RHI::RHISystemInterface::Get()->GetDevice(); @@ -681,7 +704,12 @@ namespace AZ { m_windowHandle = nullptr; m_viewportContext.reset(); + // On some platforms (e.g. Android) the main window is destroyed when the app is suspended + // but this doesn't mean that we need to exit the app. The window will be recreated when the app + // is resumed. +#if AZ_TRAIT_BOOTSTRAPSYSTEMCOMPONENT_EXIT_ON_WINDOW_CLOSE AzFramework::ApplicationRequests::Bus::Broadcast(&AzFramework::ApplicationRequests::ExitMainLoop); +#endif AzFramework::WindowNotificationBus::Handler::BusDisconnect(); } diff --git a/Gems/Atom/Bootstrap/Code/Source/BootstrapSystemComponent.h b/Gems/Atom/Bootstrap/Code/Source/BootstrapSystemComponent.h index 9fea967a77c0..6f0b616cef91 100644 --- a/Gems/Atom/Bootstrap/Code/Source/BootstrapSystemComponent.h +++ b/Gems/Atom/Bootstrap/Code/Source/BootstrapSystemComponent.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -38,6 +39,7 @@ namespace AZ class BootstrapSystemComponent : public Component , public TickBus::Handler + , public AzFramework::ApplicationLifecycleEvents::Bus::Handler , public AzFramework::WindowNotificationBus::Handler , public AzFramework::WindowSystemNotificationBus::Handler , public AzFramework::WindowSystemRequestBus::Handler @@ -84,6 +86,10 @@ namespace AZ // AzFramework::WindowSystemNotificationBus::Handler overrides ... void OnWindowCreated(AzFramework::NativeWindowHandle windowHandle) override; + // AzFramework::ApplicationLifecycleEvents::Bus::Handler overrides ... + void OnApplicationWindowCreated() override; + void OnApplicationWindowDestroy() override; + private: void Initialize(); diff --git a/Gems/Atom/Bootstrap/Code/Source/Platform/Android/BootstrapSystemComponent_Traits_Platform.h b/Gems/Atom/Bootstrap/Code/Source/Platform/Android/BootstrapSystemComponent_Traits_Platform.h index da63106e295a..1731effe0903 100644 --- a/Gems/Atom/Bootstrap/Code/Source/Platform/Android/BootstrapSystemComponent_Traits_Platform.h +++ b/Gems/Atom/Bootstrap/Code/Source/Platform/Android/BootstrapSystemComponent_Traits_Platform.h @@ -7,3 +7,4 @@ */ #define AZ_TRAIT_BOOTSTRAPSYSTEMCOMPONENT_PIPELINE_NAME "passes/LowEndRenderPipeline.azasset" +#define AZ_TRAIT_BOOTSTRAPSYSTEMCOMPONENT_EXIT_ON_WINDOW_CLOSE 0 diff --git a/Gems/Atom/Bootstrap/Code/Source/Platform/Linux/BootstrapSystemComponent_Traits_Platform.h b/Gems/Atom/Bootstrap/Code/Source/Platform/Linux/BootstrapSystemComponent_Traits_Platform.h index d467de5e5326..accd3e62ab65 100644 --- a/Gems/Atom/Bootstrap/Code/Source/Platform/Linux/BootstrapSystemComponent_Traits_Platform.h +++ b/Gems/Atom/Bootstrap/Code/Source/Platform/Linux/BootstrapSystemComponent_Traits_Platform.h @@ -7,3 +7,4 @@ */ #define AZ_TRAIT_BOOTSTRAPSYSTEMCOMPONENT_PIPELINE_NAME "passes/MainRenderPipeline.azasset" +#define AZ_TRAIT_BOOTSTRAPSYSTEMCOMPONENT_EXIT_ON_WINDOW_CLOSE 1 diff --git a/Gems/Atom/Bootstrap/Code/Source/Platform/Mac/BootstrapSystemComponent_Traits_Platform.h b/Gems/Atom/Bootstrap/Code/Source/Platform/Mac/BootstrapSystemComponent_Traits_Platform.h index d467de5e5326..accd3e62ab65 100644 --- a/Gems/Atom/Bootstrap/Code/Source/Platform/Mac/BootstrapSystemComponent_Traits_Platform.h +++ b/Gems/Atom/Bootstrap/Code/Source/Platform/Mac/BootstrapSystemComponent_Traits_Platform.h @@ -7,3 +7,4 @@ */ #define AZ_TRAIT_BOOTSTRAPSYSTEMCOMPONENT_PIPELINE_NAME "passes/MainRenderPipeline.azasset" +#define AZ_TRAIT_BOOTSTRAPSYSTEMCOMPONENT_EXIT_ON_WINDOW_CLOSE 1 diff --git a/Gems/Atom/Bootstrap/Code/Source/Platform/Windows/BootstrapSystemComponent_Traits_Platform.h b/Gems/Atom/Bootstrap/Code/Source/Platform/Windows/BootstrapSystemComponent_Traits_Platform.h index d467de5e5326..c7bb250cd0ca 100644 --- a/Gems/Atom/Bootstrap/Code/Source/Platform/Windows/BootstrapSystemComponent_Traits_Platform.h +++ b/Gems/Atom/Bootstrap/Code/Source/Platform/Windows/BootstrapSystemComponent_Traits_Platform.h @@ -6,4 +6,5 @@ * */ -#define AZ_TRAIT_BOOTSTRAPSYSTEMCOMPONENT_PIPELINE_NAME "passes/MainRenderPipeline.azasset" +#define AZ_TRAIT_BOOTSTRAPSYSTEMCOMPONENT_PIPELINE_NAME "passes/LowEndRenderPipeline.azasset" +#define AZ_TRAIT_BOOTSTRAPSYSTEMCOMPONENT_EXIT_ON_WINDOW_CLOSE 1 diff --git a/Gems/Atom/Bootstrap/Code/Source/Platform/iOS/BootstrapSystemComponent_Traits_Platform.h b/Gems/Atom/Bootstrap/Code/Source/Platform/iOS/BootstrapSystemComponent_Traits_Platform.h index da63106e295a..c7bb250cd0ca 100644 --- a/Gems/Atom/Bootstrap/Code/Source/Platform/iOS/BootstrapSystemComponent_Traits_Platform.h +++ b/Gems/Atom/Bootstrap/Code/Source/Platform/iOS/BootstrapSystemComponent_Traits_Platform.h @@ -7,3 +7,4 @@ */ #define AZ_TRAIT_BOOTSTRAPSYSTEMCOMPONENT_PIPELINE_NAME "passes/LowEndRenderPipeline.azasset" +#define AZ_TRAIT_BOOTSTRAPSYSTEMCOMPONENT_EXIT_ON_WINDOW_CLOSE 1 diff --git a/Gems/LyShine/Code/Source/UiRenderer.cpp b/Gems/LyShine/Code/Source/UiRenderer.cpp index eabf76ef973c..32166635e907 100644 --- a/Gems/LyShine/Code/Source/UiRenderer.cpp +++ b/Gems/LyShine/Code/Source/UiRenderer.cpp @@ -303,6 +303,11 @@ AZ::Matrix4x4 UiRenderer::GetModelViewProjectionMatrix() AZ::Vector2 UiRenderer::GetViewportSize() { auto viewportContext = GetViewportContext(); + if (!viewportContext) + { + return AZ::Vector2::CreateZero(); + } + auto windowContext = viewportContext->GetWindowContext(); const AZ::RHI::Viewport& viewport = windowContext->GetViewport();