From fb3940fa31000b5790eaee0a3bb9baca9ea0d1c1 Mon Sep 17 00:00:00 2001 From: mgwynn Date: Wed, 23 Jun 2021 21:05:17 -0400 Subject: [PATCH 1/5] More specific component error messaging and modes for native UI to prevent blocking dialog in some applications --- .../AzCore/AzCore/Component/Entity.cpp | 33 ++++++++++- .../AzCore/AzCore/Component/Entity.h | 2 +- .../AzCore/AzCore/Module/ModuleManager.cpp | 38 ++++++++++-- .../AzCore/AzCore/Module/ModuleManager.h | 8 ++- .../AzCore/AzCore/NativeUI/NativeUIRequests.h | 59 +++++++++++++++---- .../NativeUI/NativeUISystemComponent.cpp | 26 +++++--- .../NativeUISystemComponent_Android.cpp | 5 ++ .../NativeUI/NativeUISystemComponent_Mac.mm | 5 ++ .../NativeUISystemComponent_Windows.cpp | 5 ++ .../NativeUI/NativeUISystemComponent_iOS.mm | 5 ++ Code/Framework/AzCore/Tests/Components.cpp | 4 +- .../AzFramework/Application/Application.cpp | 2 +- Code/Sandbox/Editor/CryEdit.cpp | 15 ++++- .../Sandbox/Editor/EditorToolsApplication.cpp | 5 +- Gems/GraphCanvas/Code/Source/GraphCanvas.cpp | 3 +- .../Source/Translation/TranslationBuilder.cpp | 8 +++ 16 files changed, 186 insertions(+), 37 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/Component/Entity.cpp b/Code/Framework/AzCore/AzCore/Component/Entity.cpp index b7c161b53c..2d635b24b7 100644 --- a/Code/Framework/AzCore/AzCore/Component/Entity.cpp +++ b/Code/Framework/AzCore/AzCore/Component/Entity.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -932,13 +933,39 @@ namespace AZ return candidateInfo; } + static constexpr AZStd::string_view GetExtendedDependencySortFailureMessage(const Entity::DependencySortResult code) + { + switch (code) + { + case Entity::DependencySortResult::MissingRequiredService: + return { + "One or more components that provide required services are not in the list of components to activate.\n" + "This can often happen when an AZ::Module containing the required service wasn't loaded, check the log for details.\n" + "\n" + "This can also be caused by misconfigured services on the component or related components.\n" + "Check that the ccomponent's service functions ('GetProvidedServices', 'GetIncompatibleServices' etc) are accurate.\n"}; + case Entity::DependencySortResult::HasIncompatibleServices: + return { + "A component is incompatible with a service provided by another component.\n" + "Check that the component's service functions ('GetProvidedServices', 'GetIncompatibleServices' etc) are accurate.\n"}; + case Entity::DependencySortResult::DescriptorNotRegistered: + return { "A component descriptor was not registered with the ComponentApplication.\n" + "Make sure the component's descriptor is registered by adding it to the appropriate\n" + "AZ::Module's m_descriptors list." }; + default: + return {}; + } + } + // Shortcut for returning a FailedSortDetails as an AZ::Failure. static FailureValue FailureCode(Entity::DependencySortResult code, const char* formatMessage, ...) { va_list args; va_start(args, formatMessage); - - return Failure(Entity::FailedSortDetails{ code, AZStd::string::format_arg(formatMessage, args) }); + auto failure = Failure(Entity::FailedSortDetails{ code, AZStd::string::format_arg(formatMessage, args), + GetExtendedDependencySortFailureMessage(code) }); + va_end(args); + return failure; } // Function that creates a nice error message when incompatible components are found. @@ -1071,7 +1098,7 @@ namespace AZ ComponentDescriptorBus::EventResult(componentDescriptor, azrtti_typeid(component), &ComponentDescriptorBus::Events::GetDescriptor); if (!componentDescriptor) { - return FailureCode(DependencySortResult::MissingDescriptor, "No descriptor found for Component class '%s'.", component->RTTI_GetTypeName()); + return FailureCode(DependencySortResult::DescriptorNotRegistered, "No descriptor registered for Component class '%s'.", component->RTTI_GetTypeName()); } componentInfos.push_back(); diff --git a/Code/Framework/AzCore/AzCore/Component/Entity.h b/Code/Framework/AzCore/AzCore/Component/Entity.h index b7dcb70b9c..a4f6cdd217 100644 --- a/Code/Framework/AzCore/AzCore/Component/Entity.h +++ b/Code/Framework/AzCore/AzCore/Component/Entity.h @@ -78,7 +78,6 @@ namespace AZ HasCyclicDependency, ///< A cycle in component service dependencies was detected. HasIncompatibleServices, ///< A component is incompatible with a service provided by another component. DescriptorNotRegistered, ///< A component descriptor was not registered with the AZ::ComponentApplication. - MissingDescriptor, ///< Cannot find a component's ComponentDescriptor // Deprecated values DSR_OK = Success, @@ -320,6 +319,7 @@ namespace AZ { DependencySortResult m_code; AZStd::string m_message; + AZStd::string m_extendedMessage; }; using DependencySortOutcome = AZ::Outcome; diff --git a/Code/Framework/AzCore/AzCore/Module/ModuleManager.cpp b/Code/Framework/AzCore/AzCore/Module/ModuleManager.cpp index 0ce3ee5d8d..98fb9ceefc 100644 --- a/Code/Framework/AzCore/AzCore/Module/ModuleManager.cpp +++ b/Code/Framework/AzCore/AzCore/Module/ModuleManager.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -29,7 +30,7 @@ namespace { - static const char* s_moduleLoggingScope = "Module"; + static const char* s_moduleLoggingScope = "Module Manager"; } namespace AZ @@ -601,6 +602,25 @@ namespace AZ return {}; } + //========================================================================= + // HandleDependencySortError + //========================================================================= + void ModuleManager::HandleDependencySortError(const Entity::DependencySortOutcome& outcome) + { + // Print a short message to the log, and an extended message to the nativeUI (if available) + auto errorMessage = AZStd::string::format("Modules Entities cannot be activated.\n\n%s", outcome.GetError().m_message.c_str()); + AZ_Error(s_moduleLoggingScope, false, errorMessage.c_str()); + + auto nativeUI = AZ::Interface::Get(); + if (nativeUI) + { + errorMessage.append("\n\n"); + errorMessage.append(outcome.GetError().m_extendedMessage); + auto choice = nativeUI->DisplayBlockingDialog(s_moduleLoggingScope, errorMessage, { "Quit", "Ignore" }); + m_quitRequested = (choice == "Quit"); + } + } + //========================================================================= // OnEntityActivated //========================================================================= @@ -687,15 +707,24 @@ namespace AZ const Entity::ComponentArrayType& systemEntityComponents = systemEntity->GetComponents(); componentsToActivate.insert(componentsToActivate.begin(), systemEntityComponents.begin(), systemEntityComponents.end()); } - + // Topo sort components, activate them Entity::DependencySortOutcome outcome = ModuleEntity::DependencySort(componentsToActivate); if (!outcome.IsSuccess()) { - AZ_Error(s_moduleLoggingScope, false, "Modules Entities cannot be activated. %s", outcome.GetError().m_message.c_str()); + HandleDependencySortError(outcome); + if (m_quitRequested) + { + // Before letting the application quit, all the module entities should be restored back to init state + // because they never fully exited the activating state. + for (auto& moduleData : modulesToInit) + { + moduleData->m_moduleEntity->SetState(Entity::State::Init); + } + } return; } - + for (auto componentIt = componentsToActivate.begin(); componentIt != componentsToActivate.end(); ) { Component* component = *componentIt; @@ -711,7 +740,6 @@ namespace AZ ++componentIt; } } - // Activate the entities in the appropriate order for (Component* component : componentsToActivate) diff --git a/Code/Framework/AzCore/AzCore/Module/ModuleManager.h b/Code/Framework/AzCore/AzCore/Module/ModuleManager.h index 1cf6307b9c..0319766d2e 100644 --- a/Code/Framework/AzCore/AzCore/Module/ModuleManager.h +++ b/Code/Framework/AzCore/AzCore/Module/ModuleManager.h @@ -133,6 +133,9 @@ namespace AZ // Get the split list of system component tags specified at startup const AZStd::vector& GetSystemComponentTags() { return m_systemComponentTags; } + // Whether the user wants to quit the Application on errors rather than proceeding in a likely bad state + bool m_quitRequested = false; + protected: //////////////////////////////////////////////////////////////////////// // ModuleManagerRequestBus @@ -148,7 +151,10 @@ namespace AZ //! @return shared ptr to an ModuleData structure if the module is loaded and managed by the ModuleManager AZStd::shared_ptr GetLoadedModule(AZStd::string_view modulePath); - //////////////////////////////////////////////////////////////////////// + + //! On dependency sort errors, display error message with details. + //! Additionally send the message to NativeUI (if available) and ask user what to do, + void HandleDependencySortError(const Entity::DependencySortOutcome& outcome); //////////////////////////////////////////////////////////////////////// // EntityBus diff --git a/Code/Framework/AzCore/AzCore/NativeUI/NativeUIRequests.h b/Code/Framework/AzCore/AzCore/NativeUI/NativeUIRequests.h index f45295d221..c94ff0456c 100644 --- a/Code/Framework/AzCore/AzCore/NativeUI/NativeUIRequests.h +++ b/Code/Framework/AzCore/AzCore/NativeUI/NativeUIRequests.h @@ -17,7 +17,7 @@ namespace AZ::NativeUI { - enum AssertAction + enum class AssertAction { IGNORE_ASSERT = 0, IGNORE_ALL_ASSERTS, @@ -25,27 +25,60 @@ namespace AZ::NativeUI NONE, }; + enum class Mode + { + CONSOLE = 0, + UI, + }; + class NativeUIRequests { public: AZ_RTTI(NativeUIRequests, "{48361EE6-C1E7-4965-A13A-7425B2691817}"); virtual ~NativeUIRequests() = default; - // Waits for user to select an option before execution continues - // Returns the option string selected by the user - virtual AZStd::string DisplayBlockingDialog(const AZStd::string& /*title*/, const AZStd::string& /*message*/, const AZStd::vector& /*options*/) const { return ""; }; + //! Waits for user to select an option before execution continues + //! Returns the option string selected by the user + virtual AZStd::string DisplayBlockingDialog( + [[maybe_unused]] const AZStd::string&, + [[maybe_unused]] const AZStd::string&, + [[maybe_unused]] const AZStd::vector&) const + { + return {}; + } - // Waits for user to select an option ('Ok' or optionally 'Cancel') before execution continues - // Returns the option string selected by the user - virtual AZStd::string DisplayOkDialog(const AZStd::string& /*title*/, const AZStd::string& /*message*/, bool /*showCancel*/) const { return ""; }; + //! Waits for user to select an option ('Ok' or optionally 'Cancel') before execution continues + //! Returns the option string selected by the user + virtual AZStd::string DisplayOkDialog( + [[maybe_unused]] const AZStd::string&, + [[maybe_unused]] const AZStd::string&, + [[maybe_unused]] bool showCancel) const + { + return {}; + } - // Waits for user to select an option ('Yes', 'No' or optionally 'Cancel') before execution continues - // Returns the option string selected by the user - virtual AZStd::string DisplayYesNoDialog(const AZStd::string& /*title*/, const AZStd::string& /*message*/, bool /*showCancel*/) const { return ""; }; + //! Waits for user to select an option ('Yes', 'No' or optionally 'Cancel') before execution continues + //! Returns the option string selected by the user + virtual AZStd::string DisplayYesNoDialog( + [[maybe_unused]] const AZStd::string&, + [[maybe_unused]] const AZStd::string&, + [[maybe_unused]] bool showCancel) const + { + return {}; + } - // Displays an assert dialog box - // Returns the action selected by the user - virtual AssertAction DisplayAssertDialog(const AZStd::string& /*message*/) const { return AssertAction::NONE; }; + //! Displays an assert dialog box + //! Returns the action selected by the user + virtual AssertAction DisplayAssertDialog([[maybe_unused]] const AZStd::string&) const { return AssertAction::NONE; } + + //! Set the operation mode of the native UI systen + void SetMode(NativeUI::Mode mode) + { + m_mode = mode; + } + + protected: + NativeUI::Mode m_mode = NativeUI::Mode::CONSOLE; }; class NativeUIEBusTraits diff --git a/Code/Framework/AzCore/AzCore/NativeUI/NativeUISystemComponent.cpp b/Code/Framework/AzCore/AzCore/NativeUI/NativeUISystemComponent.cpp index bed066018a..86808cc32a 100644 --- a/Code/Framework/AzCore/AzCore/NativeUI/NativeUISystemComponent.cpp +++ b/Code/Framework/AzCore/AzCore/NativeUI/NativeUISystemComponent.cpp @@ -29,6 +29,11 @@ namespace AZ::NativeUI AssertAction NativeUISystem::DisplayAssertDialog(const AZStd::string& message) const { + if (m_mode == NativeUI::Mode::CONSOLE) + { + return AssertAction::NONE; + } + static const char* buttonNames[3] = { "Ignore", "Ignore All", "Break" }; AZStd::vector options; options.push_back(buttonNames[0]); @@ -36,8 +41,8 @@ namespace AZ::NativeUI options.push_back(buttonNames[1]); #endif options.push_back(buttonNames[2]); - AZStd::string result; - result = DisplayBlockingDialog("Assert Failed!", message, options); + + AZStd::string result = DisplayBlockingDialog("Assert Failed!", message, options); if (result.compare(buttonNames[0]) == 0) return AssertAction::IGNORE_ASSERT; @@ -51,9 +56,13 @@ namespace AZ::NativeUI AZStd::string NativeUISystem::DisplayOkDialog(const AZStd::string& title, const AZStd::string& message, bool showCancel) const { - AZStd::vector options; + if (m_mode == NativeUI::Mode::CONSOLE) + { + return {}; + } + + AZStd::vector options{ "OK" }; - options.push_back("OK"); if (showCancel) { options.push_back("Cancel"); @@ -64,10 +73,13 @@ namespace AZ::NativeUI AZStd::string NativeUISystem::DisplayYesNoDialog(const AZStd::string& title, const AZStd::string& message, bool showCancel) const { - AZStd::vector options; + if (m_mode == NativeUI::Mode::CONSOLE) + { + return {}; + } + + AZStd::vector options{ "Yes", "No" }; - options.push_back("Yes"); - options.push_back("No"); if (showCancel) { options.push_back("Cancel"); diff --git a/Code/Framework/AzCore/Platform/Android/AzCore/NativeUI/NativeUISystemComponent_Android.cpp b/Code/Framework/AzCore/Platform/Android/AzCore/NativeUI/NativeUISystemComponent_Android.cpp index b43044f0b3..abdb7c279c 100644 --- a/Code/Framework/AzCore/Platform/Android/AzCore/NativeUI/NativeUISystemComponent_Android.cpp +++ b/Code/Framework/AzCore/Platform/Android/AzCore/NativeUI/NativeUISystemComponent_Android.cpp @@ -24,6 +24,11 @@ namespace AZ { AZStd::string NativeUISystem::DisplayBlockingDialog(const AZStd::string& title, const AZStd::string& message, const AZStd::vector& options) const { + if (m_mode == NativeUI::Mode::CONSOLE) + { + return {}; + } + AZ::Android::JNI::Object object("com/amazon/lumberyard/NativeUI/LumberyardNativeUI"); object.RegisterStaticMethod("DisplayDialog", "(Landroid/app/Activity;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V"); object.RegisterStaticMethod("GetUserSelection", "()Ljava/lang/String;"); diff --git a/Code/Framework/AzCore/Platform/Mac/AzCore/NativeUI/NativeUISystemComponent_Mac.mm b/Code/Framework/AzCore/Platform/Mac/AzCore/NativeUI/NativeUISystemComponent_Mac.mm index 801adaf4ea..09d5ce1e67 100644 --- a/Code/Framework/AzCore/Platform/Mac/AzCore/NativeUI/NativeUISystemComponent_Mac.mm +++ b/Code/Framework/AzCore/Platform/Mac/AzCore/NativeUI/NativeUISystemComponent_Mac.mm @@ -28,6 +28,11 @@ namespace AZ { AZStd::string NativeUISystem::DisplayBlockingDialog(const AZStd::string& title, const AZStd::string& message, const AZStd::vector& options) const { + if (m_mode == NativeUI::Mode::CONSOLE) + { + return {}; + } + __block NSModalResponse response = -1; auto showDialog = ^() diff --git a/Code/Framework/AzCore/Platform/Windows/AzCore/NativeUI/NativeUISystemComponent_Windows.cpp b/Code/Framework/AzCore/Platform/Windows/AzCore/NativeUI/NativeUISystemComponent_Windows.cpp index f88cea5313..eaf651d2dd 100644 --- a/Code/Framework/AzCore/Platform/Windows/AzCore/NativeUI/NativeUISystemComponent_Windows.cpp +++ b/Code/Framework/AzCore/Platform/Windows/AzCore/NativeUI/NativeUISystemComponent_Windows.cpp @@ -247,6 +247,11 @@ namespace AZ { AZStd::string NativeUISystem::DisplayBlockingDialog(const AZStd::string& title, const AZStd::string& message, const AZStd::vector& options) const { + if (m_mode == NativeUI::Mode::CONSOLE) + { + return {}; + } + if (options.size() >= MAX_ITEMS) { AZ_Assert(false, "Cannot create dialog box with more than %d buttons", (MAX_ITEMS - 1)); diff --git a/Code/Framework/AzCore/Platform/iOS/AzCore/NativeUI/NativeUISystemComponent_iOS.mm b/Code/Framework/AzCore/Platform/iOS/AzCore/NativeUI/NativeUISystemComponent_iOS.mm index 62f07f7483..ce5a9ae918 100644 --- a/Code/Framework/AzCore/Platform/iOS/AzCore/NativeUI/NativeUISystemComponent_iOS.mm +++ b/Code/Framework/AzCore/Platform/iOS/AzCore/NativeUI/NativeUISystemComponent_iOS.mm @@ -20,6 +20,11 @@ namespace AZ { AZStd::string NativeUISystem::DisplayBlockingDialog(const AZStd::string& title, const AZStd::string& message, const AZStd::vector& options) const { + if (m_mode == NativeUI::Mode::CONSOLE) + { + return {}; + } + __block AZStd::string userSelection = ""; NSString* nsTitle = [NSString stringWithUTF8String:title.c_str()]; diff --git a/Code/Framework/AzCore/Tests/Components.cpp b/Code/Framework/AzCore/Tests/Components.cpp index 7801f69375..b8336072d3 100644 --- a/Code/Framework/AzCore/Tests/Components.cpp +++ b/Code/Framework/AzCore/Tests/Components.cpp @@ -909,14 +909,14 @@ namespace UnitTest EXPECT_EQ(2, m_entity->GetComponents().size()); } - TEST_F(ComponentDependency, ComponentWithoutDescriptor_FailsDueToMissingDescriptor) + TEST_F(ComponentDependency, ComponentWithoutDescriptor_FailsDueToUnregisteredDescriptor) { CreateComponents_ABCDE(); // delete ComponentB's descriptor ComponentDescriptorBus::Event(azrtti_typeid(), &ComponentDescriptorBus::Events::ReleaseDescriptor); - EXPECT_EQ(Entity::DependencySortResult::MissingDescriptor, m_entity->EvaluateDependencies()); + EXPECT_EQ(Entity::DependencySortResult::DescriptorNotRegistered, m_entity->EvaluateDependencies()); } TEST_F(ComponentDependency, StableSort_GetsSameResultsEveryTime) diff --git a/Code/Framework/AzFramework/AzFramework/Application/Application.cpp b/Code/Framework/AzFramework/AzFramework/Application/Application.cpp index bc0c9e537a..d83d402ab3 100644 --- a/Code/Framework/AzFramework/AzFramework/Application/Application.cpp +++ b/Code/Framework/AzFramework/AzFramework/Application/Application.cpp @@ -260,7 +260,7 @@ namespace AzFramework systemEntity->Activate(); AZ_Assert(systemEntity->GetState() == AZ::Entity::State::Active, "System Entity failed to activate."); - m_isStarted = true; + m_isStarted = (systemEntity->GetState() == AZ::Entity::State::Active); } void Application::PreModuleLoad() diff --git a/Code/Sandbox/Editor/CryEdit.cpp b/Code/Sandbox/Editor/CryEdit.cpp index fdeb8ce28e..dfccd87ff4 100644 --- a/Code/Sandbox/Editor/CryEdit.cpp +++ b/Code/Sandbox/Editor/CryEdit.cpp @@ -557,7 +557,6 @@ public: { bool dummy; QCommandLineParser parser; - QString appRootOverride; parser.addHelpOption(); parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); parser.setApplicationDescription(QObject::tr("Open 3D Engine")); @@ -643,7 +642,7 @@ public: option.second = parser.value(option.first.valueName); } - m_bExport = m_bExport | m_bExportTexture; + m_bExport = m_bExport || m_bExportTexture; const QStringList positionalArgs = parser.positionalArguments(); @@ -4362,6 +4361,18 @@ extern "C" int AZ_DLL_EXPORT CryEditMain(int argc, char* argv[]) { EditorInternal::EditorToolsApplication AZToolsApp(&argc, &argv); + { + CEditCommandLineInfo cmdInfo; + if (!cmdInfo.m_bAutotestMode && !cmdInfo.m_bConsoleMode && !cmdInfo.m_bExport && !cmdInfo.m_bExportTexture && + !cmdInfo.m_bNullRenderer && !cmdInfo.m_bMatEditMode && !cmdInfo.m_bTest) + { + if (auto nativeUI = AZ::Interface::Get(); nativeUI != nullptr) + { + nativeUI->SetMode(AZ::NativeUI::Mode::UI); + } + } + } + // The settings registry has been created by the AZ::ComponentApplication constructor at this point AZ::SettingsRegistryInterface& registry = *AZ::SettingsRegistry::Get(); AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddBuildSystemTargetSpecialization( diff --git a/Code/Sandbox/Editor/EditorToolsApplication.cpp b/Code/Sandbox/Editor/EditorToolsApplication.cpp index 2e3d70795a..6a56a5c040 100644 --- a/Code/Sandbox/Editor/EditorToolsApplication.cpp +++ b/Code/Sandbox/Editor/EditorToolsApplication.cpp @@ -91,10 +91,12 @@ namespace EditorInternal void EditorToolsApplication::StartCommon(AZ::Entity* systemEntity) { AzToolsFramework::ToolsApplication::StartCommon(systemEntity); + + m_StartupAborted = m_moduleManager->m_quitRequested; + if (systemEntity->GetState() != AZ::Entity::State::Active) { m_StartupAborted = true; - return; } } @@ -106,6 +108,7 @@ namespace EditorInternal AzToolsFramework::ToolsApplication::Start({}, params); if (IsStartupAborted() || !m_systemEntity) { + AzToolsFramework::ToolsApplication::Stop(); return false; } return true; diff --git a/Gems/GraphCanvas/Code/Source/GraphCanvas.cpp b/Gems/GraphCanvas/Code/Source/GraphCanvas.cpp index cc9309d71f..64972929bd 100644 --- a/Gems/GraphCanvas/Code/Source/GraphCanvas.cpp +++ b/Gems/GraphCanvas/Code/Source/GraphCanvas.cpp @@ -190,12 +190,12 @@ namespace GraphCanvas void GraphCanvasSystemComponent::Init() { - RegisterAssetHandler(); m_translationDatabase.Init(); } void GraphCanvasSystemComponent::Activate() { + RegisterAssetHandler(); RegisterTranslationBuilder(); AzFramework::AssetCatalogEventBus::Handler::BusConnect(); @@ -233,6 +233,7 @@ namespace GraphCanvas GraphCanvasRequestBus::Handler::BusDisconnect(); AZ::Data::AssetBus::MultiHandler::BusDisconnect(); + m_translationAssetWorker.Deactivate(); UnregisterAssetHandler(); } diff --git a/Gems/GraphCanvas/Code/Source/Translation/TranslationBuilder.cpp b/Gems/GraphCanvas/Code/Source/Translation/TranslationBuilder.cpp index f1fdeab62a..cbec7acabf 100644 --- a/Gems/GraphCanvas/Code/Source/Translation/TranslationBuilder.cpp +++ b/Gems/GraphCanvas/Code/Source/Translation/TranslationBuilder.cpp @@ -48,6 +48,14 @@ namespace GraphCanvas } } + void TranslationAssetWorker::Deactivate() + { + if (AZ::Data::AssetManager::Instance().GetHandler(AZ::Data::AssetType{ azrtti_typeid() })) + { + AZ::Data::AssetManager::Instance().UnregisterHandler(m_assetHandler.get()); + } + } + void TranslationAssetWorker::ShutDown() { m_isShuttingDown = true; From 692c993bdb900e756cc382a37b945aa943cc5932 Mon Sep 17 00:00:00 2001 From: mgwynn Date: Fri, 25 Jun 2021 15:34:32 -0400 Subject: [PATCH 2/5] Incorporating review comments. Adding nativeUI setting for launchers. --- .../AzCore/AzCore/NativeUI/NativeUIRequests.h | 8 ++++---- .../AzCore/NativeUI/NativeUISystemComponent.cpp | 6 +++--- .../NativeUI/NativeUISystemComponent_Windows.cpp | 2 +- Code/LauncherUnified/Launcher.cpp | 13 +++++++++++++ Code/Sandbox/Editor/CryEdit.cpp | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/NativeUI/NativeUIRequests.h b/Code/Framework/AzCore/AzCore/NativeUI/NativeUIRequests.h index c94ff0456c..e8cfb8d5fe 100644 --- a/Code/Framework/AzCore/AzCore/NativeUI/NativeUIRequests.h +++ b/Code/Framework/AzCore/AzCore/NativeUI/NativeUIRequests.h @@ -27,8 +27,8 @@ namespace AZ::NativeUI enum class Mode { - CONSOLE = 0, - UI, + DISABLED = 0, + ENABLED, }; class NativeUIRequests @@ -77,8 +77,8 @@ namespace AZ::NativeUI m_mode = mode; } - protected: - NativeUI::Mode m_mode = NativeUI::Mode::CONSOLE; + protected: + NativeUI::Mode m_mode = NativeUI::Mode::DISABLED; }; class NativeUIEBusTraits diff --git a/Code/Framework/AzCore/AzCore/NativeUI/NativeUISystemComponent.cpp b/Code/Framework/AzCore/AzCore/NativeUI/NativeUISystemComponent.cpp index 86808cc32a..80559b1270 100644 --- a/Code/Framework/AzCore/AzCore/NativeUI/NativeUISystemComponent.cpp +++ b/Code/Framework/AzCore/AzCore/NativeUI/NativeUISystemComponent.cpp @@ -29,7 +29,7 @@ namespace AZ::NativeUI AssertAction NativeUISystem::DisplayAssertDialog(const AZStd::string& message) const { - if (m_mode == NativeUI::Mode::CONSOLE) + if (m_mode == NativeUI::Mode::DISABLED) { return AssertAction::NONE; } @@ -56,7 +56,7 @@ namespace AZ::NativeUI AZStd::string NativeUISystem::DisplayOkDialog(const AZStd::string& title, const AZStd::string& message, bool showCancel) const { - if (m_mode == NativeUI::Mode::CONSOLE) + if (m_mode == NativeUI::Mode::DISABLED) { return {}; } @@ -73,7 +73,7 @@ namespace AZ::NativeUI AZStd::string NativeUISystem::DisplayYesNoDialog(const AZStd::string& title, const AZStd::string& message, bool showCancel) const { - if (m_mode == NativeUI::Mode::CONSOLE) + if (m_mode == NativeUI::Mode::DISABLED) { return {}; } diff --git a/Code/Framework/AzCore/Platform/Windows/AzCore/NativeUI/NativeUISystemComponent_Windows.cpp b/Code/Framework/AzCore/Platform/Windows/AzCore/NativeUI/NativeUISystemComponent_Windows.cpp index eaf651d2dd..33ca9cdaf0 100644 --- a/Code/Framework/AzCore/Platform/Windows/AzCore/NativeUI/NativeUISystemComponent_Windows.cpp +++ b/Code/Framework/AzCore/Platform/Windows/AzCore/NativeUI/NativeUISystemComponent_Windows.cpp @@ -247,7 +247,7 @@ namespace AZ { AZStd::string NativeUISystem::DisplayBlockingDialog(const AZStd::string& title, const AZStd::string& message, const AZStd::vector& options) const { - if (m_mode == NativeUI::Mode::CONSOLE) + if (m_mode == NativeUI::Mode::DISABLED) { return {}; } diff --git a/Code/LauncherUnified/Launcher.cpp b/Code/LauncherUnified/Launcher.cpp index c73cdd1981..6bd5dc625c 100644 --- a/Code/LauncherUnified/Launcher.cpp +++ b/Code/LauncherUnified/Launcher.cpp @@ -573,6 +573,14 @@ namespace O3DELauncher AZ_Assert(AZ::AllocatorInstance::IsReady(), "System allocator was not created or creation failed."); //Initialize the Debug trace instance to create necessary environment variables AZ::Debug::Trace::Instance().Init(); + + if (!IsDedicatedServer() && !systemInitParams.bToolMode && !systemInitParams.bTestMode) + { + if (auto nativeUI = AZ::Interface::Get(); nativeUI != nullptr) + { + nativeUI->SetMode(AZ::NativeUI::Mode::ENABLED); + } + } } if (mainInfo.m_onPostAppStart) @@ -647,6 +655,11 @@ namespace O3DELauncher ReturnCode status = ReturnCode::Success; + if (auto nativeUI = AZ::Interface::Get(); nativeUI != nullptr) + { + nativeUI->DisplayOkDialog("Test", "Test", false); + } + if (systemInitParams.pSystem) { // Process queued events before main loop. diff --git a/Code/Sandbox/Editor/CryEdit.cpp b/Code/Sandbox/Editor/CryEdit.cpp index dfccd87ff4..1c7df75a6a 100644 --- a/Code/Sandbox/Editor/CryEdit.cpp +++ b/Code/Sandbox/Editor/CryEdit.cpp @@ -4368,7 +4368,7 @@ extern "C" int AZ_DLL_EXPORT CryEditMain(int argc, char* argv[]) { if (auto nativeUI = AZ::Interface::Get(); nativeUI != nullptr) { - nativeUI->SetMode(AZ::NativeUI::Mode::UI); + nativeUI->SetMode(AZ::NativeUI::Mode::ENABLED); } } } From a9ef02d29ae07ec8139da0eb3cf0971f201cfbb1 Mon Sep 17 00:00:00 2001 From: mgwynn Date: Fri, 25 Jun 2021 15:37:14 -0400 Subject: [PATCH 3/5] Renaming nativeUI mode setting for all platforms --- .../Android/AzCore/NativeUI/NativeUISystemComponent_Android.cpp | 2 +- .../Platform/Mac/AzCore/NativeUI/NativeUISystemComponent_Mac.mm | 2 +- .../Platform/iOS/AzCore/NativeUI/NativeUISystemComponent_iOS.mm | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Code/Framework/AzCore/Platform/Android/AzCore/NativeUI/NativeUISystemComponent_Android.cpp b/Code/Framework/AzCore/Platform/Android/AzCore/NativeUI/NativeUISystemComponent_Android.cpp index abdb7c279c..3fc313f077 100644 --- a/Code/Framework/AzCore/Platform/Android/AzCore/NativeUI/NativeUISystemComponent_Android.cpp +++ b/Code/Framework/AzCore/Platform/Android/AzCore/NativeUI/NativeUISystemComponent_Android.cpp @@ -24,7 +24,7 @@ namespace AZ { AZStd::string NativeUISystem::DisplayBlockingDialog(const AZStd::string& title, const AZStd::string& message, const AZStd::vector& options) const { - if (m_mode == NativeUI::Mode::CONSOLE) + if (m_mode == NativeUI::Mode::DISABLED) { return {}; } diff --git a/Code/Framework/AzCore/Platform/Mac/AzCore/NativeUI/NativeUISystemComponent_Mac.mm b/Code/Framework/AzCore/Platform/Mac/AzCore/NativeUI/NativeUISystemComponent_Mac.mm index 09d5ce1e67..6b8be734fe 100644 --- a/Code/Framework/AzCore/Platform/Mac/AzCore/NativeUI/NativeUISystemComponent_Mac.mm +++ b/Code/Framework/AzCore/Platform/Mac/AzCore/NativeUI/NativeUISystemComponent_Mac.mm @@ -28,7 +28,7 @@ namespace AZ { AZStd::string NativeUISystem::DisplayBlockingDialog(const AZStd::string& title, const AZStd::string& message, const AZStd::vector& options) const { - if (m_mode == NativeUI::Mode::CONSOLE) + if (m_mode == NativeUI::Mode::DISABLED) { return {}; } diff --git a/Code/Framework/AzCore/Platform/iOS/AzCore/NativeUI/NativeUISystemComponent_iOS.mm b/Code/Framework/AzCore/Platform/iOS/AzCore/NativeUI/NativeUISystemComponent_iOS.mm index ce5a9ae918..9592d81d3c 100644 --- a/Code/Framework/AzCore/Platform/iOS/AzCore/NativeUI/NativeUISystemComponent_iOS.mm +++ b/Code/Framework/AzCore/Platform/iOS/AzCore/NativeUI/NativeUISystemComponent_iOS.mm @@ -20,7 +20,7 @@ namespace AZ { AZStd::string NativeUISystem::DisplayBlockingDialog(const AZStd::string& title, const AZStd::string& message, const AZStd::vector& options) const { - if (m_mode == NativeUI::Mode::CONSOLE) + if (m_mode == NativeUI::Mode::DISABLED) { return {}; } From c5dca9e232ed960521a8b3d40b4908b4c789ffa3 Mon Sep 17 00:00:00 2001 From: mgwynn Date: Fri, 25 Jun 2021 15:41:31 -0400 Subject: [PATCH 4/5] removed a call used for testing with different flags active --- Code/LauncherUnified/Launcher.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Code/LauncherUnified/Launcher.cpp b/Code/LauncherUnified/Launcher.cpp index 6bd5dc625c..17cae64142 100644 --- a/Code/LauncherUnified/Launcher.cpp +++ b/Code/LauncherUnified/Launcher.cpp @@ -655,11 +655,6 @@ namespace O3DELauncher ReturnCode status = ReturnCode::Success; - if (auto nativeUI = AZ::Interface::Get(); nativeUI != nullptr) - { - nativeUI->DisplayOkDialog("Test", "Test", false); - } - if (systemInitParams.pSystem) { // Process queued events before main loop. From 67214859465a3bab646605766372235d2e79173f Mon Sep 17 00:00:00 2001 From: mgwynn Date: Fri, 25 Jun 2021 17:03:02 -0400 Subject: [PATCH 5/5] Added parameter names to virtual function definitions for intellisense --- .../AzCore/AzCore/NativeUI/NativeUIRequests.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/NativeUI/NativeUIRequests.h b/Code/Framework/AzCore/AzCore/NativeUI/NativeUIRequests.h index e8cfb8d5fe..49a81ff18a 100644 --- a/Code/Framework/AzCore/AzCore/NativeUI/NativeUIRequests.h +++ b/Code/Framework/AzCore/AzCore/NativeUI/NativeUIRequests.h @@ -40,9 +40,9 @@ namespace AZ::NativeUI //! Waits for user to select an option before execution continues //! Returns the option string selected by the user virtual AZStd::string DisplayBlockingDialog( - [[maybe_unused]] const AZStd::string&, - [[maybe_unused]] const AZStd::string&, - [[maybe_unused]] const AZStd::vector&) const + [[maybe_unused]] const AZStd::string& title, + [[maybe_unused]] const AZStd::string& message, + [[maybe_unused]] const AZStd::vector& options) const { return {}; } @@ -50,8 +50,8 @@ namespace AZ::NativeUI //! Waits for user to select an option ('Ok' or optionally 'Cancel') before execution continues //! Returns the option string selected by the user virtual AZStd::string DisplayOkDialog( - [[maybe_unused]] const AZStd::string&, - [[maybe_unused]] const AZStd::string&, + [[maybe_unused]] const AZStd::string& title, + [[maybe_unused]] const AZStd::string& message, [[maybe_unused]] bool showCancel) const { return {}; @@ -60,8 +60,8 @@ namespace AZ::NativeUI //! Waits for user to select an option ('Yes', 'No' or optionally 'Cancel') before execution continues //! Returns the option string selected by the user virtual AZStd::string DisplayYesNoDialog( - [[maybe_unused]] const AZStd::string&, - [[maybe_unused]] const AZStd::string&, + [[maybe_unused]] const AZStd::string& title, + [[maybe_unused]] const AZStd::string& message, [[maybe_unused]] bool showCancel) const { return {}; @@ -69,7 +69,7 @@ namespace AZ::NativeUI //! Displays an assert dialog box //! Returns the action selected by the user - virtual AssertAction DisplayAssertDialog([[maybe_unused]] const AZStd::string&) const { return AssertAction::NONE; } + virtual AssertAction DisplayAssertDialog([[maybe_unused]] const AZStd::string& message) const { return AssertAction::NONE; } //! Set the operation mode of the native UI systen void SetMode(NativeUI::Mode mode)