Guard against creating a PreviewRenderer with uninitialized RPI. (#5708)

This was causing the SerializeContextTools executable to crash.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
This commit is contained in:
Mike Balfour
2021-11-17 13:30:03 -06:00
committed by GitHub
parent f5537b4b47
commit aaafb3ee34
@@ -10,6 +10,7 @@
#include <AzCore/Serialization/EditContextConstants.inl> #include <AzCore/Serialization/EditContextConstants.inl>
#include <AzCore/Serialization/SerializeContext.h> #include <AzCore/Serialization/SerializeContext.h>
#include <PreviewRenderer/PreviewRendererSystemComponent.h> #include <PreviewRenderer/PreviewRendererSystemComponent.h>
#include <Atom/RPI.Public/RPISystemInterface.h>
namespace AtomToolsFramework namespace AtomToolsFramework
{ {
@@ -53,10 +54,15 @@ namespace AtomToolsFramework
AZ::TickBus::QueueFunction( AZ::TickBus::QueueFunction(
[this]() [this]()
{ {
if (!m_previewRenderer) // Only create a preview renderer if the RPI interface is fully initialized. Otherwise the constructor will leave things
// in a bad state that can lead to crashing.
if (AZ::RPI::RPISystemInterface::Get()->IsInitialized())
{ {
m_previewRenderer.reset(aznew AtomToolsFramework::PreviewRenderer( if (!m_previewRenderer)
"PreviewRendererSystemComponent Preview Scene", "PreviewRendererSystemComponent Preview Pipeline")); {
m_previewRenderer.reset(aznew AtomToolsFramework::PreviewRenderer(
"PreviewRendererSystemComponent Preview Scene", "PreviewRendererSystemComponent Preview Pipeline"));
}
} }
}); });
} }