Selaa lähdekoodia

ATOM-17550 RPI/BakedShaderVariant: Sample crashes when exiting the ap… (#429)

* ATOM-17550 RPI/BakedShaderVariant: Sample crashes when exiting the application

The post effect entity was deleted twice if exist the app when the sample is running.
Remove the entity since it's not necessary.

The idea pattern to delete an entity created from the component, is to save the entity id and remove the entity by id. We should change all ASV code using this pattern.
This can simplify the code which we shouldn't need to connect to EntityBus and listen to OnEntityDestruction() event anymore.

Signed-off-by: Qing Tao <[email protected]>
Qing Tao 3 vuotta sitten
vanhempi
commit
cf18bb42e8

+ 4 - 20
Gem/Code/Source/CommonSampleComponentBase.cpp

@@ -77,11 +77,6 @@ namespace AtomSampleViewer
         skyboxFeatureProcessor->SetSkyboxMode(AZ::Render::SkyBoxMode::Cubemap);
         skyboxFeatureProcessor->Enable(true);
 
-        // We don't necessarily need an entity but PostProcessFeatureProcessorInterface needs an ID to retrieve ExposureControlSettingsInterface.
-        AzFramework::EntityContextRequestBus::EventResult(m_postProcessEntity, m_entityContextId, &AzFramework::EntityContextRequestBus::Events::CreateEntity, "postProcessEntity");
-        AZ_Assert(m_postProcessEntity != nullptr, "Failed to create post process entity.");
-        m_postProcessEntity->Activate();
-
         if (loadDefaultLightingPresets)
         {
             AZStd::list<AZ::Data::AssetInfo> lightingAssetInfoList;
@@ -114,7 +109,6 @@ namespace AtomSampleViewer
         }
 
         AZ::TransformNotificationBus::MultiHandler::BusConnect(m_cameraEntityId);
-        AZ::EntityBus::MultiHandler::BusConnect(m_postProcessEntity->GetId());
     }
 
     void CommonSampleComponentBase::ShutdownLightingPresets()
@@ -128,12 +122,10 @@ namespace AtomSampleViewer
         }
         m_lightHandles.clear();
 
-        ClearLightingPresets();
+        AZ::Render::PostProcessFeatureProcessorInterface* postProcessFeatureProcessor = AZ::RPI::Scene::GetFeatureProcessorForEntityContextId<AZ::Render::PostProcessFeatureProcessorInterface>(m_entityContextId);
+        postProcessFeatureProcessor->RemoveSettingsInterface(GetEntityId());
 
-        if (m_postProcessEntity)
-        {
-            DestroyEntity(m_postProcessEntity, GetEntityContextId());
-        }
+        ClearLightingPresets();
 
         skyboxFeatureProcessor->Enable(false);
 
@@ -247,7 +239,7 @@ namespace AtomSampleViewer
         AZ::Render::ImageBasedLightFeatureProcessorInterface* iblFeatureProcessor = AZ::RPI::Scene::GetFeatureProcessorForEntityContextId<AZ::Render::ImageBasedLightFeatureProcessorInterface>(m_entityContextId);
         AZ::Render::DirectionalLightFeatureProcessorInterface* directionalLightFeatureProcessor = AZ::RPI::Scene::GetFeatureProcessorForEntityContextId<AZ::Render::DirectionalLightFeatureProcessorInterface>(m_entityContextId);
 
-        AZ::Render::ExposureControlSettingsInterface* exposureControlSettingInterface = postProcessFeatureProcessor->GetOrCreateSettingsInterface(m_postProcessEntity->GetId())->GetOrCreateExposureControlSettingsInterface();
+        AZ::Render::ExposureControlSettingsInterface* exposureControlSettingInterface = postProcessFeatureProcessor->GetOrCreateSettingsInterface(GetEntityId())->GetOrCreateExposureControlSettingsInterface();
 
         Camera::Configuration cameraConfig;
         Camera::CameraRequestBus::EventResult(cameraConfig, m_cameraEntityId, &Camera::CameraRequestBus::Events::GetCameraConfiguration);
@@ -280,14 +272,6 @@ namespace AtomSampleViewer
         }
     }
 
-    void CommonSampleComponentBase::OnLightingPresetEntityShutdown(const AZ::EntityId& entityId)
-    {
-        if (m_postProcessEntity && m_postProcessEntity->GetId() == entityId)
-        {
-            m_postProcessEntity = nullptr;
-        }
-    }
-
     void CommonSampleComponentBase::PreloadAssets(const AZStd::vector<AssetCollectionAsyncLoader::AssetToLoadInfo>& assetList)
     {
         m_isAllAssetsReady = false;

+ 0 - 3
Gem/Code/Source/CommonSampleComponentBase.h

@@ -75,8 +75,6 @@ namespace AtomSampleViewer
 
         AZ::Render::MeshFeatureProcessorInterface* GetMeshFeatureProcessor() const;
 
-        void OnLightingPresetEntityShutdown(const AZ::EntityId& entityId);
-
         // Preload assets 
         void PreloadAssets(const AZStd::vector<AZ::AssetCollectionAsyncLoader::AssetToLoadInfo>& assetList);
 
@@ -126,7 +124,6 @@ namespace AtomSampleViewer
         constexpr static int32_t InvalidLightingPresetIndex = -1;
         int32_t m_currentLightingPresetIndex = InvalidLightingPresetIndex;
         bool m_useAlternateSkybox = false; //!< LightingPresets have an alternate skybox that can be used, when this is true. This is usually a blurred version of the primary skybox.
-
     };
 
 } // namespace AtomSampleViewer

+ 0 - 1
Gem/Code/Source/MeshExampleComponent.cpp

@@ -405,7 +405,6 @@ namespace AtomSampleViewer
 
     void MeshExampleComponent::OnEntityDestruction(const AZ::EntityId& entityId)
     {
-        OnLightingPresetEntityShutdown(entityId);
         AZ::EntityBus::MultiHandler::BusDisconnect(entityId);
     }
 

+ 0 - 1
Gem/Code/Source/SampleComponentManager.cpp

@@ -858,7 +858,6 @@ namespace AtomSampleViewer
                 if (ImGui::MenuItem("Exit", "Ctrl-Q"))
                 {
                     RequestExit();
-                    return;
                 }
                 if (ImGui::MenuItem("Capture Frame...", "Ctrl-P"))
                 {