瀏覽代碼

Monolithic Asset Bundle Runtime fixes (#14038)

* Updated the old Archive System handling of the OnSystemActivated
lifecycle event

Previously it would clear out the list of Archives with asset bundle
catalogs to load whenever it completed the function, whether the archive
was able to be loaded or not.

Now it uses `AZStd::erase_if` to only remove archives from the list of
archives with catalog bundles when they are actually loaded.

Signed-off-by: lumberyard-employee-dm <[email protected]>

* Moved the signaling of application lifecycle events to a runtime only
key

The new "/O3DE/Runtime/Application/LifecycleEvents" key section will be
used to signal application lifecycle events while preventing accidental
signalling of the lifecycle event whenever the registration key
sections is updated.

Signed-off-by: lumberyard-employee-dm <[email protected]>

Signed-off-by: lumberyard-employee-dm <[email protected]>
lumberyard-employee-dm 2 年之前
父節點
當前提交
56355b5b12

+ 9 - 6
Code/Framework/AzCore/AzCore/Component/ComponentApplicationLifecycle.cpp

@@ -33,10 +33,11 @@ namespace AZ::ComponentApplicationLifecycle
                 " or in *.setreg within the project", AZ_STRING_ARG(eventName), AZ_STRING_ARG(ApplicationLifecycleEventRegistrationKey));
                 " or in *.setreg within the project", AZ_STRING_ARG(eventName), AZ_STRING_ARG(ApplicationLifecycleEventRegistrationKey));
             return false;
             return false;
         }
         }
-        auto eventRegistrationKey = FixedValueString::format("%.*s/%.*s", AZ_STRING_ARG(ApplicationLifecycleEventRegistrationKey),
+        // The Settings Registry key used to signal the event is a transient runtime key which is separate from the registration key
+        auto eventSignalKey = FixedValueString::format("%.*s/%.*s", AZ_STRING_ARG(ApplicationLifecycleEventSignalKey),
             AZ_STRING_ARG(eventName));
             AZ_STRING_ARG(eventName));
 
 
-        return settingsRegistry.MergeSettings(eventValue, Format::JsonMergePatch, eventRegistrationKey);
+        return settingsRegistry.MergeSettings(eventValue, Format::JsonMergePatch, eventSignalKey);
     }
     }
 
 
     bool RegisterEvent(AZ::SettingsRegistryInterface& settingsRegistry, AZStd::string_view eventName)
     bool RegisterEvent(AZ::SettingsRegistryInterface& settingsRegistry, AZStd::string_view eventName)
@@ -74,12 +75,14 @@ namespace AZ::ComponentApplicationLifecycle
                 " or in *.setreg within the project", AZ_STRING_ARG(eventName), AZ_STRING_ARG(ApplicationLifecycleEventRegistrationKey));
                 " or in *.setreg within the project", AZ_STRING_ARG(eventName), AZ_STRING_ARG(ApplicationLifecycleEventRegistrationKey));
             return false;
             return false;
         }
         }
-        auto eventNameRegistrationKey = FixedValueString::format("%.*s/%.*s", AZ_STRING_ARG(ApplicationLifecycleEventRegistrationKey),
-            AZ_STRING_ARG(eventName));
-        auto lifecycleCallback = [callback = AZStd::move(callback), eventNameRegistrationKey](
+
+        // The signal key is used for invoking the handler
+        auto lifecycleCallback = [callback = AZStd::move(callback),
+            eventNameSignalKey = FixedValueString::format("%.*s/%.*s",
+                AZ_STRING_ARG(ApplicationLifecycleEventSignalKey), AZ_STRING_ARG(eventName))](
             const AZ::SettingsRegistryInterface::NotifyEventArgs& notifyEventArgs)
             const AZ::SettingsRegistryInterface::NotifyEventArgs& notifyEventArgs)
         {
         {
-            if (notifyEventArgs.m_jsonKeyPath == eventNameRegistrationKey)
+            if (notifyEventArgs.m_jsonKeyPath == eventNameSignalKey)
             {
             {
                 callback(notifyEventArgs);
                 callback(notifyEventArgs);
             }
             }

+ 7 - 1
Code/Framework/AzCore/AzCore/Component/ComponentApplicationLifecycle.h

@@ -13,9 +13,15 @@
 
 
 namespace AZ::ComponentApplicationLifecycle
 namespace AZ::ComponentApplicationLifecycle
 {
 {
-    //! Root Key where lifecycle events should be registered under
+    //! Root Key used to determine where lifecycle events are registered underneath
     inline constexpr AZStd::string_view ApplicationLifecycleEventRegistrationKey = "/O3DE/Application/LifecycleEvents";
     inline constexpr AZStd::string_view ApplicationLifecycleEventRegistrationKey = "/O3DE/Application/LifecycleEvents";
 
 
+    //! Root Key to use for signaling lifecycle events
+    //! This key section is runtime only and will not be merged into the aggregated setreg file
+    //! produced by the SettingsRegistryBuilder
+    //! It is used to separately from the registration key section, to avoid the scenario
+    //! where registering a lifecycle event would result in signaling the event.
+    inline constexpr AZStd::string_view ApplicationLifecycleEventSignalKey = "/O3DE/Runtime/Application/LifecycleEvents";
 
 
     //! Validates that the event @eventName is stored in the array at ApplicationLifecycleEventRegistrationKey
     //! Validates that the event @eventName is stored in the array at ApplicationLifecycleEventRegistrationKey
     //! @param settingsRegistry registry where @eventName will be searched
     //! @param settingsRegistry registry where @eventName will be searched

+ 6 - 4
Code/Framework/AzFramework/AzFramework/Archive/Archive.cpp

@@ -2183,13 +2183,13 @@ namespace AZ::IO
 
 
     void Archive::OnSystemEntityActivated()
     void Archive::OnSystemEntityActivated()
     {
     {
-        for (const auto& archiveInfo : m_archivesWithCatalogsToLoad)
+        auto LoadArchives = [this](const AZ::IO::Archive::ArchivesWithCatalogsToLoad& archiveInfo)
         {
         {
             AZStd::intrusive_ptr<INestedArchive> archive =
             AZStd::intrusive_ptr<INestedArchive> archive =
                 OpenArchive(archiveInfo.m_fullPath, archiveInfo.m_bindRoot, archiveInfo.m_flags, nullptr);
                 OpenArchive(archiveInfo.m_fullPath, archiveInfo.m_bindRoot, archiveInfo.m_flags, nullptr);
             if (!archive)
             if (!archive)
             {
             {
-                continue;
+                return false;
             }
             }
 
 
             ZipDir::CachePtr pZip = static_cast<NestedArchive*>(archive.get())->GetCache();
             ZipDir::CachePtr pZip = static_cast<NestedArchive*>(archive.get())->GetCache();
@@ -2209,7 +2209,9 @@ namespace AZ::IO
                     archiveNotifications->BundleOpened(bundleName, bundleManifest, nextBundle.c_str(), bundleCatalog);
                     archiveNotifications->BundleOpened(bundleName, bundleManifest, nextBundle.c_str(), bundleCatalog);
                 },
                 },
                 archiveInfo.m_strFileName.c_str(), bundleManifest, archiveInfo.m_nextBundle, bundleCatalog);
                 archiveInfo.m_strFileName.c_str(), bundleManifest, archiveInfo.m_nextBundle, bundleCatalog);
-        }
-        m_archivesWithCatalogsToLoad.clear();
+
+            return true;
+        };
+        AZStd::erase_if(m_archivesWithCatalogsToLoad, LoadArchives);
     }
     }
 }
 }