Skip to content

Commit 23bfbc2

Browse files
committed
Detect whether the Property Editor is being instanced in the Editor or in a Unit Test and handle deletion differently.
Signed-off-by: Danilo Aimini <[email protected]>
1 parent a345dfb commit 23bfbc2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI_Internals.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,20 @@ namespace AzToolsFramework
206206
{
207207
if (m_widget)
208208
{
209-
delete m_widget;
210-
m_widget = nullptr;
209+
// Detect whether this is being run in the Editor or during a Unit Test.
210+
AZ::ApplicationTypeQuery appType;
211+
AZ::ComponentApplicationBus::Broadcast(&AZ::ComponentApplicationBus::Events::QueryApplicationType, appType);
212+
if (appType.IsValid() && !appType.IsEditor())
213+
{
214+
// In Unit Tests, immediately delete the widget to prevent triggering the leak detection mechanism.
215+
delete m_widget;
216+
m_widget = nullptr;
217+
}
218+
else
219+
{
220+
// In the Editor, use deleteLater as it is more stable.
221+
m_widget->deleteLater();
222+
}
211223
}
212224
IndividualPropertyHandlerEditNotifications::Bus::Handler::BusDisconnect();
213225
}

0 commit comments

Comments
 (0)