Fixing a crash when applying a profile with missing monitors

This commit is contained in:
s_falahati
2018-10-20 03:53:43 +03:30
parent c6de48b178
commit 04f1449409
2 changed files with 13 additions and 6 deletions

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
@ -23,7 +24,7 @@ namespace HeliosDisplayManagement.Shared
{
private static Profile _currentProfile;
public static Version Version = new Version(1, 0);
public static Version Version = new Version(2, 0);
static Profile()
{
@ -235,15 +236,21 @@ namespace HeliosDisplayManagement.Shared
{
// ignored
}
Thread.Sleep(19000);
PathInfo.ApplyPathInfos(Paths.Select(path => path.ToPathInfo()), true, true);
Thread.Sleep(9000);
Thread.Sleep(18000);
var pathInfos = Paths.Select(path => path.ToPathInfo()).Where(info => info != null).ToArray();
if (!pathInfos.Any())
{
throw new InvalidOperationException(@"Display configuration changed since this profile is created. Please re-create this profile.");
}
PathInfo.ApplyPathInfos(pathInfos, true, true, true);
Thread.Sleep(10000);
RefreshActiveStatus();
return true;
}
catch
catch (Exception ex)
{
RefreshActiveStatus();
MessageBox.Show(ex.Message, @"Profile", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
}

View File

@ -84,7 +84,7 @@ namespace HeliosDisplayManagement.Shared.Topology
public PathInfo ToPathInfo()
{
var targets = Targets.Select(target => target.ToPathTargetInfo()).ToArray();
var targets = Targets.Select(target => target.ToPathTargetInfo()).Where(info => info != null).ToArray();
if (targets.Any())
return new PathInfo(new PathDisplaySource(targets.First().DisplayTarget.Adapter, SourceId), Position,
Resolution, PixelFormat, targets);