Fixed infinite recursion when adding prefabs
While processing prefabs into spawnables new prefabs can be added for later processing. Because the new prefabs were immediately added to the list of prefabs it could happen that the new prefabs would be added to the active processor for processing, which could lead to infinite recursion. Adding prefabs while iterating prefabs now delays the addition until the iteration has completed. Signed-off-by: AMZN-koppersr <82230785+AMZN-koppersr@users.noreply.github.com>
This commit is contained in:
+24
-2
@@ -32,8 +32,24 @@ namespace AzToolsFramework::Prefab::PrefabConversionUtils
|
||||
|
||||
bool PrefabProcessorContext::AddPrefab(AZStd::string prefabName, PrefabDom prefab)
|
||||
{
|
||||
auto result = m_prefabs.emplace(AZStd::move(prefabName), AZStd::move(prefab));
|
||||
return result.second;
|
||||
if (!m_isIterating)
|
||||
{
|
||||
auto result = m_prefabs.emplace(AZStd::move(prefabName), AZStd::move(prefab));
|
||||
return result.second;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto it = m_prefabs.find(prefabName);
|
||||
if (it == m_prefabs.end())
|
||||
{
|
||||
auto result = m_pendingPrefabAdditions.emplace(AZStd::move(prefabName), AZStd::move(prefab));
|
||||
return result.second;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PrefabProcessorContext::ListPrefabs(const AZStd::function<void(AZStd::string_view, PrefabDom&)>& callback)
|
||||
@@ -43,7 +59,13 @@ namespace AzToolsFramework::Prefab::PrefabConversionUtils
|
||||
{
|
||||
callback(it.first, it.second);
|
||||
}
|
||||
|
||||
m_isIterating = false;
|
||||
for (auto& prefab : m_pendingPrefabAdditions)
|
||||
{
|
||||
m_prefabs.emplace(AZStd::move(prefab.first), AZStd::move(prefab.second));
|
||||
}
|
||||
m_pendingPrefabAdditions.clear();
|
||||
}
|
||||
|
||||
void PrefabProcessorContext::ListPrefabs(const AZStd::function<void(AZStd::string_view, const PrefabDom&)>& callback) const
|
||||
|
||||
+1
@@ -134,6 +134,7 @@ namespace AzToolsFramework::Prefab::PrefabConversionUtils
|
||||
AZ::Data::AssetLoadBehavior ToAssetLoadBehavior(EntityAliasSpawnableLoadBehavior loadBehavior) const;
|
||||
|
||||
NamedPrefabContainer m_prefabs;
|
||||
NamedPrefabContainer m_pendingPrefabAdditions;
|
||||
SpawnableEntityAliasStore m_entityAliases;
|
||||
ProcessedObjectStoreContainer m_products;
|
||||
ProductAssetDependencyContainer m_registeredProductAssetDependencies;
|
||||
|
||||
Reference in New Issue
Block a user