SystemComponent.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <iostream>
  9. #include <AzCore/Component/EntityUtils.h>
  10. #include <AzCore/Console/IConsole.h>
  11. #include <AzCore/Serialization/EditContext.h>
  12. #include <AzCore/Serialization/Json/RegistrationContext.h>
  13. #include <AzCore/Serialization/SerializeContext.h>
  14. #include <AzCore/Serialization/Utils.h>
  15. #include <Libraries/Libraries.h>
  16. #include <ScriptCanvas/Asset/RuntimeAsset.h>
  17. #include <ScriptCanvas/Core/Contract.h>
  18. #include <ScriptCanvas/Core/Graph.h>
  19. #include <ScriptCanvas/Core/Node.h>
  20. #include <ScriptCanvas/Core/Nodeable.h>
  21. #include <ScriptCanvas/Core/Slot.h>
  22. #include <ScriptCanvas/Execution/ExecutionPerformanceTimer.h>
  23. #include <ScriptCanvas/Execution/Interpreted/ExecutionInterpretedAPI.h>
  24. #include <ScriptCanvas/Execution/RuntimeComponent.h>
  25. #include <ScriptCanvas/Serialization/DatumSerializer.h>
  26. #include <ScriptCanvas/Serialization/BehaviorContextObjectSerializer.h>
  27. #include <ScriptCanvas/Serialization/RuntimeVariableSerializer.h>
  28. #include <ScriptCanvas/SystemComponent.h>
  29. #include <ScriptCanvas/Variable/GraphVariableManagerComponent.h>
  30. #include <ScriptCanvas/Core/Contracts/MathOperatorContract.h>
  31. #include <ScriptCanvas/Libraries/Spawning/CreateSpawnTicketNodeable.h>
  32. #include <ScriptCanvas/Libraries/Spawning/DespawnNodeable.h>
  33. #include <ScriptCanvas/Libraries/Spawning/SpawnNodeable.h>
  34. #if defined(SC_EXECUTION_TRACE_ENABLED)
  35. #include <ScriptCanvas/Asset/ExecutionLogAsset.h>
  36. #endif
  37. #include <AutoGen/ScriptCanvasAutoGenRegistry.h>
  38. namespace ScriptCanvasSystemComponentCpp
  39. {
  40. #if !defined(_RELEASE)
  41. const int k_infiniteLoopDetectionMaxIterations = 1000000;
  42. const int k_maxHandlerStackDepth = 25;
  43. #else
  44. const int k_infiniteLoopDetectionMaxIterations = 10000000;
  45. const int k_maxHandlerStackDepth = 100;
  46. #endif
  47. bool IsDeprecated(const AZ::AttributeArray& attributes)
  48. {
  49. bool isDeprecated{};
  50. if (auto isDeprecatedAttributePtr = AZ::FindAttribute(AZ::Script::Attributes::Deprecated, attributes))
  51. {
  52. AZ::AttributeReader(nullptr, isDeprecatedAttributePtr).Read<bool>(isDeprecated);
  53. }
  54. return isDeprecated;
  55. }
  56. }
  57. namespace ScriptCanvas
  58. {
  59. AZ_ENUM_CLASS(PerformanceReportFileStream,
  60. None,
  61. Stdout,
  62. Stderr
  63. );
  64. }
  65. namespace ScriptCanvas
  66. {
  67. // Console Variable to determine where the scriptcanvas output performance report is sent
  68. AZ_CVAR(PerformanceReportFileStream, sc_outputperformancereport, PerformanceReportFileStream::None, {}, AZ::ConsoleFunctorFlags::Null,
  69. "Determines where the Script Canvas performance report should be output.");
  70. void SystemComponent::Reflect(AZ::ReflectContext* context)
  71. {
  72. ScriptCanvasModel::Instance().Reflect(context);
  73. VersionData::Reflect(context);
  74. Nodeable::Reflect(context);
  75. SourceHandle::Reflect(context);
  76. ReflectLibraries(context);
  77. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  78. {
  79. serialize->Class<SystemComponent, AZ::Component>()
  80. ->Version(1)
  81. // ScriptCanvas avoids a use dependency on the AssetBuilderSDK. Therefore the Crc is used directly to register this component with the Gem builder
  82. ->Attribute(AZ::Edit::Attributes::SystemComponentTags, AZStd::vector<AZ::Crc32>({ AZ_CRC_CE("AssetBuilder") }))
  83. ->Field("m_infiniteLoopDetectionMaxIterations", &SystemComponent::m_infiniteLoopDetectionMaxIterations)
  84. ->Field("maxHandlerStackDepth", &SystemComponent::m_maxHandlerStackDepth)
  85. ;
  86. if (AZ::EditContext* ec = serialize->GetEditContext())
  87. {
  88. ec->Class<SystemComponent>("Script Canvas", "Script Canvas System Component")
  89. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  90. ->Attribute(AZ::Edit::Attributes::Category, "Scripting")
  91. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  92. ->DataElement(AZ::Edit::UIHandlers::Default, &SystemComponent::m_infiniteLoopDetectionMaxIterations, "Infinite Loop Protection Max Iterations", "Script Canvas will avoid infinite loops by detecting potentially re-entrant conditions that execute up to this number of iterations.")
  93. ->DataElement(AZ::Edit::UIHandlers::Default, &SystemComponent::m_maxHandlerStackDepth, "Max Handler Stack Depth", "Script Canvas will avoid infinite loops at run-time by detecting sending Ebus Events while handling said Events. This limits the stack depth of the broadcast.")
  94. ->Attribute(AZ::Edit::Attributes::Min, 1000) // Safeguard user given value is valid
  95. ;
  96. }
  97. }
  98. if (AZ::JsonRegistrationContext* jsonContext = azrtti_cast<AZ::JsonRegistrationContext*>(context))
  99. {
  100. jsonContext->Serializer<AZ::DatumSerializer>()->HandlesType<Datum>();
  101. jsonContext->Serializer<AZ::BehaviorContextObjectSerializer>()->HandlesType<BehaviorContextObject>();
  102. jsonContext->Serializer<AZ::RuntimeVariableSerializer>()->HandlesType<RuntimeVariable>();
  103. }
  104. #if defined(SC_EXECUTION_TRACE_ENABLED)
  105. ExecutionLogData::Reflect(context);
  106. ExecutionLogAsset::Reflect(context);
  107. #endif//defined(SC_EXECUTION_TRACE_ENABLED)
  108. }
  109. void SystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  110. {
  111. provided.push_back(AZ_CRC_CE("ScriptCanvasService"));
  112. }
  113. void SystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  114. {
  115. (void)incompatible;
  116. }
  117. void SystemComponent::GetRequiredServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required)
  118. {
  119. // \todo configure the application to require these services
  120. // required.push_back(AZ_CRC_CE("AssetDatabaseService"));
  121. // required.push_back(AZ_CRC_CE("ScriptService"));
  122. }
  123. void SystemComponent::GetDependentServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& dependent)
  124. {
  125. }
  126. void SystemComponent::Init()
  127. {
  128. RegisterCreatableTypes();
  129. m_infiniteLoopDetectionMaxIterations = ScriptCanvasSystemComponentCpp::k_infiniteLoopDetectionMaxIterations;
  130. m_maxHandlerStackDepth = ScriptCanvasSystemComponentCpp::k_maxHandlerStackDepth;
  131. }
  132. void SystemComponent::Activate()
  133. {
  134. SystemRequestBus::Handler::BusConnect();
  135. AZ::BehaviorContext* behaviorContext{};
  136. AZ::ComponentApplicationBus::BroadcastResult(behaviorContext, &AZ::ComponentApplicationRequests::GetBehaviorContext);
  137. if (behaviorContext)
  138. {
  139. AZ::BehaviorContextBus::Handler::BusConnect(behaviorContext);
  140. }
  141. if (IsAnyScriptInterpreted()) // or if is the editor...
  142. {
  143. Execution::ActivateInterpreted();
  144. }
  145. SafeRegisterPerformanceTracker();
  146. }
  147. void SystemComponent::Deactivate()
  148. {
  149. AZ::BehaviorContextBus::Handler::BusDisconnect();
  150. SystemRequestBus::Handler::BusDisconnect();
  151. ModPerformanceTracker()->CalculateReports();
  152. Execution::PerformanceTrackingReport report = ModPerformanceTracker()->GetGlobalReport();
  153. const double ready = aznumeric_caster(report.timing.initializationTime);
  154. const double instant = aznumeric_caster(report.timing.executionTime);
  155. const double latent = aznumeric_caster(report.timing.latentTime);
  156. const double total = aznumeric_caster(report.timing.totalTime);
  157. FILE* performanceReportStream = nullptr;
  158. if (auto console = AZ::Interface<AZ::IConsole>::Get(); console != nullptr)
  159. {
  160. if (PerformanceReportFileStream performanceOutputOption;
  161. console->GetCvarValue("sc_outputperformancereport", performanceOutputOption) == AZ::GetValueResult::Success)
  162. {
  163. switch (performanceOutputOption)
  164. {
  165. case PerformanceReportFileStream::None:
  166. performanceReportStream = nullptr;
  167. break;
  168. case PerformanceReportFileStream::Stdout:
  169. performanceReportStream = stdout;
  170. break;
  171. case PerformanceReportFileStream::Stderr:
  172. performanceReportStream = stderr;
  173. break;
  174. }
  175. }
  176. }
  177. if (performanceReportStream != nullptr)
  178. {
  179. fprintf(performanceReportStream, "Global ScriptCanvas Performance Report:\n");
  180. fprintf(performanceReportStream, "[ INITIALIZE] %s\n", AZStd::fixed_string<32>::format("%7.3f ms", ready / 1000.0).c_str());
  181. fprintf(performanceReportStream, "[ EXECUTION] %s\n", AZStd::fixed_string<32>::format("%7.3f ms", instant / 1000.0).c_str());
  182. fprintf(performanceReportStream, "[ LATENT] %s\n", AZStd::fixed_string<32>::format("%7.3f ms", latent / 1000.0).c_str());
  183. fprintf(performanceReportStream, "[ TOTAL] %s\n", AZStd::fixed_string<32>::format("%7.3f ms", total / 1000.0).c_str());
  184. }
  185. SafeUnregisterPerformanceTracker();
  186. }
  187. bool SystemComponent::IsScriptUnitTestingInProgress()
  188. {
  189. return m_scriptBasedUnitTestingInProgress;
  190. }
  191. void SystemComponent::MarkScriptUnitTestBegin()
  192. {
  193. m_scriptBasedUnitTestingInProgress = true;
  194. }
  195. void SystemComponent::MarkScriptUnitTestEnd()
  196. {
  197. m_scriptBasedUnitTestingInProgress = false;
  198. }
  199. void SystemComponent::CreateEngineComponentsOnEntity(AZ::Entity* entity)
  200. {
  201. if (entity)
  202. {
  203. auto graph = entity->CreateComponent<Graph>();
  204. entity->CreateComponent<GraphVariableManagerComponent>(graph->GetScriptCanvasId());
  205. }
  206. }
  207. Graph* SystemComponent::CreateGraphOnEntity(AZ::Entity* graphEntity)
  208. {
  209. return graphEntity ? graphEntity->CreateComponent<Graph>() : nullptr;
  210. }
  211. ScriptCanvas::Graph* SystemComponent::MakeGraph()
  212. {
  213. AZ::Entity* graphEntity = aznew AZ::Entity("Script Canvas");
  214. ScriptCanvas::Graph* graph = graphEntity->CreateComponent<ScriptCanvas::Graph>();
  215. return graph;
  216. }
  217. ScriptCanvasId SystemComponent::FindScriptCanvasId(AZ::Entity* graphEntity)
  218. {
  219. auto* graph = graphEntity ? AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Graph>(graphEntity) : nullptr;
  220. return graph ? graph->GetScriptCanvasId() : ScriptCanvasId();
  221. }
  222. ScriptCanvas::Node* SystemComponent::GetNode(const AZ::EntityId& nodeId, const AZ::Uuid& typeId)
  223. {
  224. AZ::Entity* entity = nullptr;
  225. AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationRequests::FindEntity, nodeId);
  226. if (entity)
  227. {
  228. ScriptCanvas::Node* node = azrtti_cast<ScriptCanvas::Node*>(entity->FindComponent(typeId));
  229. return node;
  230. }
  231. return nullptr;
  232. }
  233. ScriptCanvas::Node* SystemComponent::CreateNodeOnEntity(const AZ::EntityId& entityId, ScriptCanvasId scriptCanvasId, const AZ::Uuid& nodeType)
  234. {
  235. AZ::SerializeContext* serializeContext = nullptr;
  236. AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
  237. AZ_Assert(serializeContext, "Failed to retrieve application serialize context");
  238. const AZ::SerializeContext::ClassData* classData = serializeContext->FindClassData(nodeType);
  239. AZ_Assert(classData, "Type %s is not registered in the serialization context", nodeType.ToString<AZStd::string>().data());
  240. if (classData)
  241. {
  242. AZ::Entity* nodeEntity = nullptr;
  243. AZ::ComponentApplicationBus::BroadcastResult(nodeEntity, &AZ::ComponentApplicationRequests::FindEntity, entityId);
  244. ScriptCanvas::Node* node = reinterpret_cast<ScriptCanvas::Node*>(classData->m_factory->Create(classData->m_name));
  245. AZ_Assert(node, "ClassData (%s) does not correspond to a supported ScriptCanvas Node", classData->m_name);
  246. if (node && nodeEntity)
  247. {
  248. nodeEntity->SetName(classData->m_name);
  249. nodeEntity->AddComponent(node);
  250. }
  251. GraphRequestBus::Event(scriptCanvasId, &GraphRequests::AddNode, nodeEntity->GetId());
  252. return node;
  253. }
  254. return nullptr;
  255. }
  256. void SystemComponent::AddOwnedObjectReference(const void* object, BehaviorContextObject* behaviorContextObject)
  257. {
  258. if (object == nullptr)
  259. {
  260. return;
  261. }
  262. LockType lock(m_ownedObjectsByAddressMutex);
  263. [[maybe_unused]] auto emplaceResult = m_ownedObjectsByAddress.emplace(object, behaviorContextObject);
  264. AZ_Assert(emplaceResult.second, "Adding second owned reference to memory");
  265. }
  266. BehaviorContextObject* SystemComponent::FindOwnedObjectReference(const void* object)
  267. {
  268. if (object == nullptr)
  269. {
  270. return nullptr;
  271. }
  272. LockType lock(m_ownedObjectsByAddressMutex);
  273. auto iter = m_ownedObjectsByAddress.find(object);
  274. return iter == m_ownedObjectsByAddress.end() ? nullptr : iter->second;
  275. }
  276. void SystemComponent::RemoveOwnedObjectReference(const void* object)
  277. {
  278. if (object == nullptr)
  279. {
  280. return;
  281. }
  282. LockType lock(m_ownedObjectsByAddressMutex);
  283. m_ownedObjectsByAddress.erase(object);
  284. }
  285. AZStd::pair<DataRegistry::Createability, TypeProperties> SystemComponent::GetCreatibility(AZ::SerializeContext* serializeContext, AZ::BehaviorClass* behaviorClass)
  286. {
  287. TypeProperties typeProperties;
  288. bool canCreate{};
  289. // BehaviorContext classes with the ExcludeFrom attribute with a value of the ExcludeFlags::List is not creatable
  290. const AZ::u64 exclusionFlags = AZ::Script::Attributes::ExcludeFlags::List;
  291. auto excludeClassAttributeData = azrtti_cast<const AZ::Edit::AttributeData<AZ::Script::Attributes::ExcludeFlags>*>(AZ::FindAttribute(AZ::Script::Attributes::ExcludeFrom, behaviorClass->m_attributes));
  292. const AZ::u64 flags = excludeClassAttributeData ? excludeClassAttributeData->Get(nullptr) : 0;
  293. bool listOnly = ((flags & AZ::Script::Attributes::ExcludeFlags::ListOnly) == AZ::Script::Attributes::ExcludeFlags::ListOnly); // ListOnly exclusions may create variables
  294. canCreate = listOnly || (!excludeClassAttributeData || (!(flags & exclusionFlags)));
  295. canCreate = canCreate && (serializeContext->FindClassData(behaviorClass->m_typeId));
  296. canCreate = canCreate && !ScriptCanvasSystemComponentCpp::IsDeprecated(behaviorClass->m_attributes);
  297. if (canCreate)
  298. {
  299. for (auto base : behaviorClass->m_baseClasses)
  300. {
  301. if (AZ::Component::TYPEINFO_Uuid() == base)
  302. {
  303. canCreate = false;
  304. break; // only out of the for : base classes loop. DO NOT break out of the parent loop.
  305. }
  306. }
  307. }
  308. // Assets are not safe enough for variable creation, yet. They can be created with one Az type (Data::Asset<T>), but set to nothing.
  309. // When read back in, they will (if lucky) just be Data::Asset<Data>, which breaks type safety at best, and requires a lot of sanity checking.
  310. // This is NOT blacked at the createable types or BehaviorContext level, since they could be used to at least pass information through,
  311. // and may be used other scripting contexts.
  312. AZ::IRttiHelper* rttiHelper = behaviorClass->m_azRtti;
  313. if (rttiHelper && rttiHelper->GetGenericTypeId() == azrtti_typeid<AZ::Data::Asset>())
  314. {
  315. canCreate = false;
  316. }
  317. if (AZ::FindAttribute(AZ::ScriptCanvasAttributes::AllowInternalCreation, behaviorClass->m_attributes))
  318. {
  319. canCreate = true;
  320. typeProperties.m_isTransient = true;
  321. }
  322. // create able variables must have full memory support
  323. canCreate = canCreate &&
  324. (behaviorClass->m_allocate
  325. && behaviorClass->m_cloner
  326. && behaviorClass->m_mover
  327. && behaviorClass->m_destructor
  328. && behaviorClass->m_deallocate) &&
  329. AZStd::none_of(behaviorClass->m_baseClasses.begin(), behaviorClass->m_baseClasses.end(), [](const AZ::TypeId& base) { return azrtti_typeid<AZ::Component>() == base; });
  330. if (!canCreate)
  331. {
  332. return { DataRegistry::Createability::None , TypeProperties{} };
  333. }
  334. else if (!AZ::FindAttribute(AZ::ScriptCanvasAttributes::VariableCreationForbidden, behaviorClass->m_attributes))
  335. {
  336. return { DataRegistry::Createability::SlotAndVariable, typeProperties };
  337. }
  338. else
  339. {
  340. return { DataRegistry::Createability::SlotOnly, typeProperties };
  341. }
  342. }
  343. void SystemComponent::RegisterCreatableTypes()
  344. {
  345. AZ::SerializeContext* serializeContext{};
  346. AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
  347. AZ_Assert(serializeContext, "Serialize Context should not be missing at this point");
  348. AZ::BehaviorContext* behaviorContext{};
  349. AZ::ComponentApplicationBus::BroadcastResult(behaviorContext, &AZ::ComponentApplicationRequests::GetBehaviorContext);
  350. AZ_Assert(behaviorContext, "Behavior Context should not be missing at this point");
  351. auto dataRegistry = ScriptCanvas::GetDataRegistry();
  352. for (const auto& classIter : behaviorContext->m_classes)
  353. {
  354. auto createability = GetCreatibility(serializeContext, classIter.second);
  355. if (createability.first != DataRegistry::Createability::None)
  356. {
  357. dataRegistry->RegisterType(classIter.second->m_typeId, createability.second, createability.first);
  358. }
  359. }
  360. }
  361. void SystemComponent::OnAddClass(const char*, AZ::BehaviorClass* behaviorClass)
  362. {
  363. auto dataRegistry = ScriptCanvas::GetDataRegistry();
  364. if (!dataRegistry)
  365. {
  366. AZ_Warning("ScriptCanvas", false, "Data registry not available. Can't register new class.");
  367. return;
  368. }
  369. AZ::SerializeContext* serializeContext{};
  370. AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
  371. AZ_Assert(serializeContext, "Serialize Context missing. Can't register new class.");
  372. auto createability = GetCreatibility(serializeContext, behaviorClass);
  373. if (createability.first != DataRegistry::Createability::None)
  374. {
  375. dataRegistry->RegisterType(behaviorClass->m_typeId, createability.second, createability.first);
  376. }
  377. }
  378. void SystemComponent::OnRemoveClass(const char*, AZ::BehaviorClass* behaviorClass)
  379. {
  380. // The data registry might not be available when unloading the ScriptCanvas module
  381. auto dataRegistry = ScriptCanvas::GetDataRegistry();
  382. if (dataRegistry)
  383. {
  384. dataRegistry->UnregisterType(behaviorClass->m_typeId);
  385. }
  386. }
  387. void SystemComponent::SetInterpretedBuildConfiguration(BuildConfiguration config)
  388. {
  389. Execution::SetInterpretedExecutionMode(config);
  390. }
  391. AZ::EnvironmentVariable<Execution::PerformanceTracker*> SystemComponent::s_perfTracker;
  392. AZStd::shared_mutex SystemComponent::s_perfTrackerMutex;
  393. Execution::PerformanceTracker* SystemComponent::ModPerformanceTracker()
  394. {
  395. // First attempt to use the module-static reference; take a read lock to check it.
  396. // This is the fast path which won't block.
  397. {
  398. AZStd::shared_lock<AZStd::shared_mutex> lock(s_perfTrackerMutex);
  399. if (s_perfTracker)
  400. {
  401. return s_perfTracker.Get();
  402. }
  403. }
  404. // If the instance doesn't exist (which means we could be in a different module),
  405. // take the full lock and request it.
  406. AZStd::unique_lock<AZStd::shared_mutex> lock(s_perfTrackerMutex);
  407. s_perfTracker = AZ::Environment::FindVariable<Execution::PerformanceTracker*>(s_trackerName);
  408. return s_perfTracker ? s_perfTracker.Get() : nullptr;
  409. }
  410. void SystemComponent::SafeRegisterPerformanceTracker()
  411. {
  412. if (ModPerformanceTracker())
  413. {
  414. return;
  415. }
  416. AZStd::unique_lock<AZStd::shared_mutex> lock(s_perfTrackerMutex);
  417. auto tracker = aznew Execution::PerformanceTracker();
  418. s_perfTracker = AZ::Environment::CreateVariable<Execution::PerformanceTracker*>(s_trackerName);
  419. s_perfTracker.Get() = tracker;
  420. }
  421. void SystemComponent::SafeUnregisterPerformanceTracker()
  422. {
  423. auto performanceTracker = ModPerformanceTracker();
  424. if (!performanceTracker)
  425. {
  426. return;
  427. }
  428. AZStd::unique_lock<AZStd::shared_mutex> lock(s_perfTrackerMutex);
  429. *s_perfTracker = nullptr;
  430. s_perfTracker.Reset();
  431. delete performanceTracker;
  432. }
  433. }