Ref T709, return 0 if there is no camera position (nullptr)

This commit is contained in:
Klaus Basan
2019-07-31 18:37:56 +02:00
committed by Mat Sutcliffe
parent b539964906
commit 2df218ff99

View File

@@ -885,11 +885,18 @@ namespace XSwiftBus
if (isLosingControl == 1) if (isLosingControl == 1)
{ {
// traffic->m_planeViewCallsign.clear(); // traffic->m_planeViewCallsign.clear();
traffic->m_followPlaneViewCallsign.clear();
return 0; return 0;
} }
if (cameraPosition) // nothing we can do
if (!cameraPosition)
{ {
ERROR_LOG("No camera object");
traffic->m_followPlaneViewCallsign.clear();
return 0;
}
// Ideally we would like to test against right mouse button, but X-Plane SDK does not // Ideally we would like to test against right mouse button, but X-Plane SDK does not
// allow that. // allow that.
if (!traffic->m_deltaCameraPosition.isInitialized || traffic->m_isSpacePressed) if (!traffic->m_deltaCameraPosition.isInitialized || traffic->m_isSpacePressed)
@@ -926,9 +933,11 @@ namespace XSwiftBus
} }
else else
{ {
if (traffic->m_planesByCallsign.empty()) { return 0; } // paranoia
const auto planeIt = traffic->m_planesByCallsign.find(traffic->m_followPlaneViewCallsign); const auto planeIt = traffic->m_planesByCallsign.find(traffic->m_followPlaneViewCallsign);
if (planeIt == traffic->m_planesByCallsign.end()) { return 0; } if (planeIt == traffic->m_planesByCallsign.end()) { return 0; }
const Plane *plane = planeIt->second; const Plane *plane = planeIt->second;
if (!plane) { return 0; }
XPLMWorldToLocal(plane->position.lat, plane->position.lon, plane->position.elevation * kFtToMeters, &lx, &ly, &lz); XPLMWorldToLocal(plane->position.lat, plane->position.lon, plane->position.elevation * kFtToMeters, &lx, &ly, &lz);
if (!isValidPosition(plane->position)) if (!isValidPosition(plane->position))
@@ -954,7 +963,6 @@ namespace XSwiftBus
INFO_LOG("Pos: " + pos2String(cameraPosition)); INFO_LOG("Pos: " + pos2String(cameraPosition));
return 0; return 0;
} }
}
// Return 1 to indicate we want to keep controlling the camera. // Return 1 to indicate we want to keep controlling the camera.
return 1; return 1;