Skip to content

Commit

Permalink
Fix crash that could occasionally occur when exiting Flight Simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
astenlund committed Oct 7, 2020
1 parent 7034ce2 commit 63de517
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions FlightSim/FlightSimAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ private void DisconnectInternal(bool failure)
{
UnsubscribeEvents();

_simConnect?.Dispose();
_simConnect = null;

_attitudeTimer?.Dispose();
_attitudeTimer = null;

_simConnect?.Dispose();
_simConnect = null;

StateChanged?.Invoke(failure);
}

Expand Down Expand Up @@ -126,12 +126,19 @@ private void RegisterTrafficStruct()

private void RequestAttitudeData(object? _)
{
_simConnect?.RequestDataOnSimObject(
REQUEST.Attitude, DEFINITION.Attitude,
SimConnect.SIMCONNECT_OBJECT_ID_USER,
SIMCONNECT_PERIOD.ONCE,
SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT,
0, 0, 0);
try
{
_simConnect?.RequestDataOnSimObject(
REQUEST.Attitude, DEFINITION.Attitude,
SimConnect.SIMCONNECT_OBJECT_ID_USER,
SIMCONNECT_PERIOD.ONCE,
SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT,
0, 0, 0);
}
catch (COMException e)
{
Console.Error.WriteLine("Exception caught: " + e);
}
}

private void SimConnect_OnRecvEventObjectAddremove(SimConnect sender, SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE data)
Expand Down

0 comments on commit 63de517

Please sign in to comment.