Fix race condition crash with the gradient preview. (#7530)

When duplicating an entity with a Gradient SurfaceData Component, it's possible to get a hang/crash due to a race condition between entity deactivation and the gradient preview job refresh. This change ensures that the preview job is canceled on deactivation.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
monroegm-disable-blank-issue-2
Mike Balfour 4 years ago committed by GitHub
parent 2a977510de
commit f79fa57b4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,6 +11,7 @@
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
#include <LmbrCentral/Dependency/DependencyNotificationBus.h>
#include <GradientSignal/Ebuses/GradientPreviewRequestBus.h>
namespace GradientSignal
{
@ -61,6 +62,12 @@ namespace GradientSignal
void EditorGradientSurfaceDataComponent::Deactivate()
{
// Make sure any previews for this entity aren't currently trying to refresh. Otherwise, the preview job could call
// back into our FilterFunc lambda below after the entity has already been destroyed.
AZ::EntityId canceledEntity;
GradientSignal::GradientPreviewRequestBus::EventResult(
canceledEntity, GetEntityId(), &GradientSignal::GradientPreviewRequestBus::Events::CancelRefresh);
// If the preview shouldn't be active, use an invalid entityId
m_gradientEntityId = AZ::EntityId();
AzFramework::EntityDebugDisplayEventBus::Handler::BusDisconnect();

Loading…
Cancel
Save