From 3207e909f7c66bd5d1b0ae2bf3da1f07c5827975 Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Thu, 17 Feb 2022 10:54:43 -0600 Subject: [PATCH] Added error handling for unsupported pixel formats on an image gradient Signed-off-by: Chris Galvan --- .../UI/PropertyEditor/PropertyAssetCtrl.hxx | 2 +- .../Source/Components/ImageGradientComponent.cpp | 12 ++++++++++++ .../Editor/EditorStreamingImageAssetCtrl.cpp | 14 ++++++++++++++ .../Source/Editor/EditorStreamingImageAssetCtrl.h | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/PropertyAssetCtrl.hxx b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/PropertyAssetCtrl.hxx index 14326fcc6e..cd6f8e636e 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/PropertyAssetCtrl.hxx +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/PropertyAssetCtrl.hxx @@ -246,7 +246,7 @@ namespace AzToolsFramework virtual void PopupAssetPicker(); virtual void PickAssetSelectionFromDialog(AssetSelectionModel& selection, QWidget* parent); void OnClearButtonClicked(); - void UpdateAssetDisplay(); + virtual void UpdateAssetDisplay(); void OnLineEditFocus(bool focus); virtual void OnEditButtonClicked(); void OnThumbnailClicked(); diff --git a/Gems/GradientSignal/Code/Source/Components/ImageGradientComponent.cpp b/Gems/GradientSignal/Code/Source/Components/ImageGradientComponent.cpp index ea17679df1..bdde9a0957 100644 --- a/Gems/GradientSignal/Code/Source/Components/ImageGradientComponent.cpp +++ b/Gems/GradientSignal/Code/Source/Components/ImageGradientComponent.cpp @@ -226,6 +226,18 @@ namespace GradientSignal return; } + // If we have loaded in an old image asset with an unsupported pixel format, + // don't try to access the image data because there will be spam of asserts, + // so just log an error message and bail out + AZ::RHI::Format format = m_configuration.m_imageAsset->GetImageDescriptor().m_format; + bool isFormatSupported = AZ::RPI::IsImageDataPixelAPISupported(format); + if (!isFormatSupported) + { + AZ_Error("GradientSignal", false, "Image asset (%s) has an unsupported pixel format: %s", + m_configuration.m_imageAsset.GetHint().c_str(), AZ::RHI::ToString(format)); + return; + } + m_imageData = m_configuration.m_imageAsset->GetSubImageData(0, 0); } diff --git a/Gems/GradientSignal/Code/Source/Editor/EditorStreamingImageAssetCtrl.cpp b/Gems/GradientSignal/Code/Source/Editor/EditorStreamingImageAssetCtrl.cpp index 9b088b159a..f22229fc39 100644 --- a/Gems/GradientSignal/Code/Source/Editor/EditorStreamingImageAssetCtrl.cpp +++ b/Gems/GradientSignal/Code/Source/Editor/EditorStreamingImageAssetCtrl.cpp @@ -76,6 +76,20 @@ namespace GradientSignal } } + void StreamingImagePropertyAssetCtrl::UpdateAssetDisplay() + { + AzToolsFramework::PropertyAssetCtrl::UpdateAssetDisplay(); + + // If there is a valid asset selected but it's not a supported pixel format, + // show the error message state for this property + if (m_selectedAssetID.IsValid() && !Internal::IsImageDataPixelAPISupportedForAsset(m_selectedAssetID)) + { + UpdateErrorButtonWithMessage( + AZStd::string::format("Image asset (%s) has an unsupported pixel format", GetCurrentAssetHint().c_str()) + ); + } + } + AZ::u32 StreamingImagePropertyHandler::GetHandlerName() const { return AZ_CRC_CE("GradientSignalStreamingImageAsset"); diff --git a/Gems/GradientSignal/Code/Source/Editor/EditorStreamingImageAssetCtrl.h b/Gems/GradientSignal/Code/Source/Editor/EditorStreamingImageAssetCtrl.h index a5c0a199ce..90fac61565 100644 --- a/Gems/GradientSignal/Code/Source/Editor/EditorStreamingImageAssetCtrl.h +++ b/Gems/GradientSignal/Code/Source/Editor/EditorStreamingImageAssetCtrl.h @@ -44,6 +44,7 @@ namespace GradientSignal public Q_SLOTS: void OnAutocomplete(const QModelIndex& index) override; + void UpdateAssetDisplay() override; }; //! We need a custom asset property handler for the AZ::RPI::StreamingImageAsset on our