Added AMD ADL Exception handling

This commit is contained in:
Terry MacDonald 2021-06-19 19:39:50 +12:00
parent a01d5defaa
commit 9065735ad9
2 changed files with 399 additions and 378 deletions

View File

@ -605,7 +605,11 @@ namespace DisplayMagicianShared.AMD
int NumberOfDisplays = 0;
List<string> displayIdentifiers = new List<string>();
IntPtr AdapterBuffer = IntPtr.Zero;
IntPtr DisplayBuffer = IntPtr.Zero;
try
{
if (null != ADL.ADL2_Adapter_NumberOfAdapters_Get)
{
ADL.ADL2_Adapter_NumberOfAdapters_Get(_adlContextHandle, ref NumberOfAdapters);
@ -618,7 +622,7 @@ namespace DisplayMagicianShared.AMD
ADLAdapterInfoX2Array OSAdapterInfoData;
OSAdapterInfoData = new ADLAdapterInfoX2Array();
IntPtr AdapterBuffer = IntPtr.Zero;
if (ADL.ADL2_Adapter_AdapterInfoX4_Get != null)
{
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: ADL2_Adapter_AdapterInfoX4_Get DLL function exists.");
@ -720,7 +724,7 @@ namespace DisplayMagicianShared.AMD
if (ADL.ADL2_Display_DisplayInfo_Get != null)
{
IntPtr DisplayBuffer = IntPtr.Zero;
DisplayBuffer = IntPtr.Zero;
// Force the display detection and get the Display Info. Use 0 as last parameter to NOT force detection
ADLRet = ADL.ADL2_Display_DisplayInfo_Get(_adlContextHandle, oneAdapter.AdapterIndex, ref NumberOfDisplays, out DisplayBuffer, 0);
@ -1024,7 +1028,7 @@ namespace DisplayMagicianShared.AMD
SharedLogger.logger.Warn($"ADLWrapper/GenerateProfileDisplayIdentifiers: Error running ADL2_Display_DisplayInfo_Get on Adapter #{oneAdapter.AdapterIndex}: {ADL.ConvertADLReturnValueIntoWords(ADLRet)}");
}
// Release the memory for the DisplayInfo structure
if (IntPtr.Zero != DisplayBuffer)
if (DisplayBuffer != IntPtr.Zero)
Marshal.FreeCoTaskMem(DisplayBuffer);
}
}
@ -1040,7 +1044,7 @@ namespace DisplayMagicianShared.AMD
}
}
// Release the memory for the AdapterInfo structure
if (IntPtr.Zero != AdapterBuffer)
if (AdapterBuffer != IntPtr.Zero)
{
Marshal.FreeCoTaskMem(AdapterBuffer);
}
@ -1054,5 +1058,22 @@ namespace DisplayMagicianShared.AMD
return null;
}
}
catch (Exception ex)
{
SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception somewhere while trying to generate an AMD display identifier");
// Release the memory for the AdapterInfo structure
if (AdapterBuffer != IntPtr.Zero)
{
Marshal.FreeCoTaskMem(AdapterBuffer);
}
// Release the memory for the DisplayInfo structure
if (DisplayBuffer != IntPtr.Zero)
{
Marshal.FreeCoTaskMem(DisplayBuffer);
}
return null;
}
}
}
}

View File

@ -799,7 +799,7 @@ namespace DisplayMagicianShared
List<string> displayIdentifiers = new List<string>();
bool isNvidia = false;
bool isAMD = false;
//bool isAMD = false;
// If the Video Card is an NVidia, then we should generate specific NVidia displayIdentifiers
@ -918,7 +918,7 @@ namespace DisplayMagicianShared
// else if there is an AMD video card then we use that mode
else if (AMDLibrary.IsInstalled)
{
isAMD = true;
//isAMD = true;
SharedLogger.logger.Debug($"ProfileRepository/GenerateProfileDisplayIdentifiers: The video card is an AMD video card.");
// Needs a lot of work here! We need to check if the AMD returned the right stuff, and then use Windows if there is an error.
return AMDLibrary.GenerateProfileDisplayIdentifiers();