Skip to content

Commit e5de28e

Browse files
committed
Introduce different pathways to prevent tests from failing due to memory leak detection.
Signed-off-by: Danilo Aimini <[email protected]>
1 parent 38cff4d commit e5de28e

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
1919
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
2020
#include <AzToolsFramework/Entity/EditorEntityInfoBus.h>
21+
#include <AzToolsFramework/Entity/EditorEntitySortComponent.h>
2122
#include <AzToolsFramework/Entity/PrefabEditorEntityOwnershipInterface.h>
2223
#include <AzToolsFramework/Entity/ReadOnly/ReadOnlyEntityInterface.h>
2324
#include <AzToolsFramework/Prefab/EditorPrefabComponent.h>
@@ -36,7 +37,7 @@
3637
#include <AzToolsFramework/Prefab/Undo/PrefabUndoUpdateLink.h>
3738
#include <AzToolsFramework/Prefab/PrefabUndoHelpers.h>
3839
#include <AzToolsFramework/ToolsComponents/TransformComponent.h>
39-
#include <AzToolsFramework/Entity/EditorEntitySortComponent.h>
40+
#include <AzToolsFramework/ViewportSelection/EditorTransformComponentSelectionRequestBus.h>
4041

4142
#include <QString>
4243
#include <QTimer>
@@ -45,6 +46,14 @@ namespace AzToolsFramework
4546
{
4647
namespace Prefab
4748
{
49+
PrefabPublicHandler::PrefabPublicHandler()
50+
{
51+
// Detect whether this is being run in the Editor or during a Unit Test.
52+
AZ::ApplicationTypeQuery appType;
53+
AZ::ComponentApplicationBus::Broadcast(&AZ::ComponentApplicationBus::Events::QueryApplicationType, appType);
54+
m_isRunningInEditor = (!appType.IsValid() || appType.IsEditor());
55+
}
56+
4857
void PrefabPublicHandler::RegisterPrefabPublicHandlerInterface()
4958
{
5059
m_prefabFocusHandler.RegisterPrefabFocusInterface();
@@ -1342,14 +1351,24 @@ namespace AzToolsFramework
13421351
auto selectionUndo = aznew SelectionCommand(duplicatedEntityAndInstanceIds, "Select Duplicated Entities/Instances");
13431352
selectionUndo->SetParent(undoBatch.GetUndoBatch());
13441353

1345-
QTimer::singleShot(
1346-
0,
1347-
[duplicatedEntityAndInstanceIds]()
1348-
{
1349-
ToolsApplicationRequestBus::Broadcast(
1350-
&ToolsApplicationRequestBus::Events::SetSelectedEntities, duplicatedEntityAndInstanceIds);
1351-
}
1352-
);
1354+
// Only delay selection in the Editor to ensure the manipulators in the viewport are refreshed correctly.
1355+
if (m_isRunningInEditor)
1356+
{
1357+
QTimer::singleShot(
1358+
0,
1359+
[duplicatedEntityAndInstanceIds]()
1360+
{
1361+
ToolsApplicationRequestBus::Broadcast(
1362+
&ToolsApplicationRequestBus::Events::SetSelectedEntities, duplicatedEntityAndInstanceIds);
1363+
}
1364+
);
1365+
}
1366+
else
1367+
{
1368+
ToolsApplicationRequestBus::Broadcast(
1369+
&ToolsApplicationRequestBus::Events::SetSelectedEntities, duplicatedEntityAndInstanceIds);
1370+
}
1371+
13531372
}
13541373

13551374
return AZ::Success(AZStd::move(duplicatedEntityAndInstanceIds));

Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace AzToolsFramework
3939
AZ_CLASS_ALLOCATOR(PrefabPublicHandler, AZ::SystemAllocator);
4040
AZ_RTTI(PrefabPublicHandler, "{35802943-6B60-430F-9DED-075E3A576A25}", PrefabPublicInterface);
4141

42+
PrefabPublicHandler();
43+
4244
void RegisterPrefabPublicHandlerInterface();
4345
void UnregisterPrefabPublicHandlerInterface();
4446

@@ -212,6 +214,8 @@ namespace AzToolsFramework
212214
PrefabFocusHandler m_prefabFocusHandler;
213215

214216
uint64_t m_newEntityCounter = 1;
217+
218+
bool m_isRunningInEditor = true;
215219
};
216220
} // namespace Prefab
217221
} // namespace AzToolsFramework

0 commit comments

Comments
 (0)