Skip to content

Commit

Permalink
Merge pull request #168 from EVEJay/master
Browse files Browse the repository at this point in the history
Added multiple checks to catch null exceptions in different places.
  • Loading branch information
Slazanger authored Jul 9, 2024
2 parents b6c5820 + 12161b9 commit 83a6ee8
Showing 1 changed file with 81 additions and 23 deletions.
104 changes: 81 additions & 23 deletions SMT/Overlay.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Windows.Threading;
using Windows.Services;
using Microsoft.IdentityModel.Tokens;
using Microsoft.VisualBasic.Logging;
using NHotkey;
using SMT.EVEData;
using static SMT.EVEData.Navigation;
Expand Down Expand Up @@ -487,10 +488,12 @@ private float CalculatedOverlaySystemSize(string systemName)
if (gathererMode)
return overlaySystemSizeGatherer;

if (systemName == currentPlayersSystemData[OverlayCharacter]?.system?.Name)
if (OverlayCharacter != null &&
currentPlayersSystemData[OverlayCharacter].system != null &&
systemName == currentPlayersSystemData[OverlayCharacter]?.system?.Name)
return overlaySystemSizeHunter * overlayCurrentSystemSizeHunterModifier;

if (currentPlayersSystemData.Any(s => s.Value.system.Name == systemName))
if (currentPlayersSystemData.Where(s => s.Value.system != null).Any(s => s.Value.system.Name == systemName))
{
return overlaySystemSizeHunter * overlayAdditionalCharacterSystemSizeHunterModifier;
}
Expand Down Expand Up @@ -642,37 +645,81 @@ private void UpdateCharacterData()
}
}

private void UpdatePlayerLocations(object sender, EventArgs e)
/// <summary>
/// Check if all chars in the internal list are still registered
/// with the main window. Clean up or close if not.
/// </summary>
private void ValidateCharacters()
{
if (OverlayCharacter != null)
// It is ok to have the overlay character be null.
if (OverlayCharacter == null)
{
if (currentPlayersSystemData[OverlayCharacter].system == null)
{
RefreshCurrentView();
}
else if (OverlayCharacter.Location != currentPlayersSystemData[OverlayCharacter].system.Name || routeLines.Count > 0 && (routeLines.Count != OverlayCharacter.ActiveRoute.Count - 1))
return;
}

if (!mainWindow.EVEManager.LocalCharacters.Contains(OverlayCharacter))
{
Close();
}

List<LocalCharacter> pruneCharacters = new();
foreach (KeyValuePair<LocalCharacter, OverlaySystemData> characterPair in currentPlayersSystemData)
{
if (!mainWindow.EVEManager.LocalCharacters.Contains(characterPair.Key))
{
RefreshCurrentView();
pruneCharacters.Add(characterPair.Key);
}
else
}

foreach (LocalCharacter pruneCharacter in pruneCharacters)
{
currentPlayersSystemData.Remove(pruneCharacter);
}
}

private void UpdatePlayerLocations(object sender, EventArgs e)
{
ValidateCharacters();

try
{
if (OverlayCharacter != null)
{
foreach (LocalCharacter additionalCharacter in mainWindow.EVEManager.LocalCharacters)
if (currentPlayersSystemData[OverlayCharacter].system == null)
{
if (additionalCharacter != OverlayCharacter)
RefreshCurrentView();
}
else if (OverlayCharacter.Location != currentPlayersSystemData[OverlayCharacter].system.Name ||
routeLines.Count > 0 && (routeLines.Count != OverlayCharacter.ActiveRoute.Count - 1))
{
RefreshCurrentView();
}
else
{
foreach (LocalCharacter additionalCharacter in mainWindow.EVEManager.LocalCharacters)
{
if (additionalCharacter.Location != currentPlayersSystemData[additionalCharacter].system.Name)
if (additionalCharacter != OverlayCharacter)
{
RefreshCurrentView();
break;
if (additionalCharacter.Location !=
currentPlayersSystemData[additionalCharacter].system.Name)
{
RefreshCurrentView();
break;
}
}
}
}
}
}
}
catch (Exception)
{
}
}

private void UpdateDataOverlay(object sender, EventArgs e)
{
ValidateCharacters();

try
{
UpdateIntelData();
Expand Down Expand Up @@ -1002,21 +1049,32 @@ private void UpdateSystemList()
// Gather data
currentPlayersSystemData.Clear();
string currentLocation = OverlayCharacter.Location;
EVEData.System currentSystem = mainWindow.EVEManager.GetEveSystem(currentLocation);
currentPlayersSystemData.Add(OverlayCharacter, new OverlaySystemData(currentSystem));
foreach (LocalCharacter additionalChar in mainWindow.EVEManager.LocalCharacters)

// Bail out if the system name is empty or null. May happen during update.
if (String.IsNullOrEmpty(currentLocation))
{
if (!currentPlayersSystemData.ContainsKey(additionalChar))
currentPlayersSystemData.Add(additionalChar, new OverlaySystemData(mainWindow.EVEManager.GetEveSystem(additionalChar.Location)));
ClearView();
return;
}


EVEData.System currentSystem = mainWindow.EVEManager.GetEveSystem(currentLocation);

// Bail out if the system does not exist. I.e. wormhole systems.
if (currentSystem == null)
{
//on your way out, mop up everything thats left
ClearView();
return;
}

currentPlayersSystemData.Add(OverlayCharacter, new OverlaySystemData(currentSystem));
foreach (LocalCharacter additionalChar in mainWindow.EVEManager.LocalCharacters)
{
if (!currentPlayersSystemData.ContainsKey(additionalChar))
currentPlayersSystemData.Add(additionalChar, new OverlaySystemData(mainWindow.EVEManager.GetEveSystem(additionalChar.Location)));
}



List<List<OverlaySystemData>> hierarchie = new List<List<OverlaySystemData>>();

Expand Down

0 comments on commit 83a6ee8

Please sign in to comment.