From 79d0109e5ac1b7718bd38209b028fd94642a4bb1 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 31 Jul 2019 20:21:53 +0200 Subject: [PATCH] Ref T709, check on screen w/h and report warning instead of info. Also log missing traffic object. --- src/xswiftbus/traffic.cpp | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/xswiftbus/traffic.cpp b/src/xswiftbus/traffic.cpp index 440c33cc5..df0025256 100644 --- a/src/xswiftbus/traffic.cpp +++ b/src/xswiftbus/traffic.cpp @@ -879,13 +879,17 @@ namespace XSwiftBus int CTraffic::orbitPlaneFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon) { - auto *traffic = static_cast(refcon); - - if (!traffic) { return 0; } // just in case if (isLosingControl == 1) { - // traffic->m_planeViewCallsign.clear(); - traffic->m_followPlaneViewCallsign.clear(); + // do NOT use refcon here, might be invalid + INFO_LOG("Loosing camera control"); + return 0; + } + + auto *traffic = static_cast(refcon); + if (!traffic) + { + ERROR_LOG("Cannot convert CTraffic object"); return 0; } @@ -907,6 +911,14 @@ namespace XSwiftBus // fixme: In a future update, change the orbit only while right mouse button is pressed. XPLMGetScreenSize(&w, &h); XPLMGetMouseLocation(&x, &y); + + // avoid follow aircraft in too small windows + if (w < 100 || h < 100) + { + WARNING_LOG("Screen w/h too small " + std::to_string(w) + "/" + std::to_string(h)); + return 0; + } + traffic->m_deltaCameraPosition.heading = 360.0 * static_cast(x) / static_cast(w); traffic->m_deltaCameraPosition.pitch = 20.0 * ((static_cast(y) / static_cast(h)) * 2.0 - 1.0); @@ -942,8 +954,8 @@ namespace XSwiftBus XPLMWorldToLocal(plane->position.lat, plane->position.lon, plane->position.elevation * kFtToMeters, &lx, &ly, &lz); if (!isValidPosition(plane->position)) { - INFO_LOG("Invalid follow aircraft position for " + plane->callsign); - INFO_LOG("Pos: " + pos2String(plane->position)); + WARNING_LOG("Invalid follow aircraft position for " + plane->callsign); + WARNING_LOG("Pos: " + pos2String(plane->position)); return 0; } } @@ -961,8 +973,8 @@ namespace XSwiftBus if (!isValidPosition(cameraPosition)) { - INFO_LOG("Invalid camera aircraft position"); - INFO_LOG("Pos: " + pos2String(cameraPosition)); + WARNING_LOG("Invalid camera aircraft position"); + WARNING_LOG("Pos: " + pos2String(cameraPosition)); return 0; }