From ea50e1def76edd90cf33dae263abe8f71dfde16f Mon Sep 17 00:00:00 2001 From: Robert Manuszewski Date: Tue, 5 Aug 2014 13:03:54 -0400 Subject: [PATCH] Added code to handle COM crashes when detecting physical processor count in UBT [CL 2244406 by Robert Manuszewski in Main branch] --- .../UnrealBuildTool/System/LocalExecutor.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Engine/Source/Programs/UnrealBuildTool/System/LocalExecutor.cs b/Engine/Source/Programs/UnrealBuildTool/System/LocalExecutor.cs index aea663c915b1..b53c6ef40d46 100644 --- a/Engine/Source/Programs/UnrealBuildTool/System/LocalExecutor.cs +++ b/Engine/Source/Programs/UnrealBuildTool/System/LocalExecutor.cs @@ -339,9 +339,21 @@ namespace UnrealBuildTool int NumCores = 0; if (!Utils.IsRunningOnMono) { - foreach(var Item in new System.Management.ManagementObjectSearcher("Select * from Win32_Processor").Get()) + try { - NumCores += int.Parse(Item["NumberOfCores"].ToString()); + using (var Mos = new System.Management.ManagementObjectSearcher("Select * from Win32_Processor")) + { + var MosCollection = Mos.Get(); + foreach (var Item in MosCollection) + { + NumCores += int.Parse(Item["NumberOfCores"].ToString()); + } + } + } + catch (Exception Ex) + { + Log.TraceWarning("Unable to get the number of Cores: {0}", Ex.ToString()); + Log.TraceWarning("Falling back to processor count."); } } // On some systems this requires a hot fix to work so we fall back to using the (logical) processor count.