Skip to content

Commit

Permalink
Unsubscribe from onVesselStandardModification on destruction as `On…
Browse files Browse the repository at this point in the history
…UnloadVessel` may not be called
  • Loading branch information
dkavolis committed Aug 30, 2022
1 parent cc85b26 commit efec236
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions FerramAerospaceResearch/FARAeroComponents/FARVesselAero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private void CalculateAndApplyVesselAeroProperties()

if (velocityWorldVector.NearlyEqual(lastSimResults.VelocityVector) &&
(FARAtmosphere.IsCustom
// Custom atmospheres are not guaranteed to be independent of latitude and longitude
// Custom atmospheres are not guaranteed to be independent of latitude and longitude
? position.NearlyEqual(lastSimResults.Position)
: altitude.NearlyEqual(lastSimResults.Position.z)))
{
Expand All @@ -308,7 +308,8 @@ private void CalculateAndApplyVesselAeroProperties()
var dummy = new FARCenterQuery();

//Calculate main gas properties
GasProperties properties = FARAtmosphere.GetGasProperties(vessel.mainBody, position, Planetarium.GetUniversalTime());
GasProperties properties =
FARAtmosphere.GetGasProperties(vessel.mainBody, position, Planetarium.GetUniversalTime());

if (properties.Pressure <= 0 || properties.Temperature <= 0)
{
Expand Down Expand Up @@ -523,15 +524,21 @@ public override void OnLoadVessel()
base.OnLoadVessel();
}

public override void OnUnloadVessel()
private void Unsubscribe()
{
GameEvents.onVesselStandardModification.Remove(VesselUpdateEvent);
}

public override void OnUnloadVessel()
{
Unsubscribe();

base.OnUnloadVessel();
}

private void OnDestroy()
{
Unsubscribe();
DisableModule();
}

Expand Down

0 comments on commit efec236

Please sign in to comment.