Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added multiple checks to catch null exceptions in different places. #168

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -269,7 +270,7 @@

private int overlayDepth = 8;
private Dictionary<LocalCharacter, OverlaySystemData> currentPlayersSystemData = new ();
private OverlaySystemData currentPlayerSystemData;

Check warning on line 273 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used

Check warning on line 273 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used

Check warning on line 273 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used

Check warning on line 273 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used
private OverlayCanvasData canvasData = new OverlayCanvasData();

private float intelUrgentPeriod = 300;
Expand Down Expand Up @@ -487,10 +488,12 @@
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 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 @@
// 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
Loading