Skip to content

Commit

Permalink
Merge #2984 Fix null reference in recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
politas committed Feb 2, 2020
2 parents b0c4b3d + 944818b commit 204ba8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Features

### Bugfixes
- [GUI] Fix null reference in recommendations (#2984 by: HebaruSan; reviewed: politas)

### Internal

Expand Down
11 changes: 8 additions & 3 deletions GUI/Controls/ChooseRecommendedMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,16 @@ private void RecommendedModsListView_SelectedIndexChanged(object sender, EventAr
OnSelectedItemsChanged(RecommendedModsListView.SelectedItems);
}
}

private void RecommendedModsListView_ItemChecked(object sender, EventArgs e)
{
var conflicts = FindConflicts();
foreach (var item in RecommendedModsListView.Items.Cast<ListViewItem>())
foreach (var item in RecommendedModsListView.Items.Cast<ListViewItem>()
// Apparently ListView handes AddRange by:
// 1. Expanding the Items list to the new size by filling it with nulls
// 2. One by one, replace each null with a real item and call _ItemChecked
// ... so the Items list can contain null!!
.Where(it => it != null))
{
item.BackColor = conflicts.ContainsKey(item.Tag as CkanModule)
? Color.LightCoral
Expand All @@ -94,7 +99,7 @@ private Dictionary<CkanModule, String> FindConflicts()
return new RelationshipResolver(
RecommendedModsListView.CheckedItems.Cast<ListViewItem>()
.Select(item => item.Tag as CkanModule)
.Distinct(),
.Distinct(),
new CkanModule[] { },
conflictOptions, registry, kspVersion
).ConflictList;
Expand Down

0 comments on commit 204ba8b

Please sign in to comment.