Added code to handle COM crashes when detecting physical processor count in UBT

[CL 2244406 by Robert Manuszewski in Main branch]
This commit is contained in:
Robert Manuszewski
2014-08-05 13:03:54 -04:00
committed by UnrealBot
parent f7eddba5cb
commit ea50e1def7

View File

@@ -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.