From 37b357f282d5ecb5d5c4e973f45a9fc35e02a119 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 25 Jul 2014 13:44:36 +1000 Subject: [PATCH] AP_Terrain: prevent valgrind error when terrain not available --- libraries/AP_Terrain/TerrainGCS.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/AP_Terrain/TerrainGCS.cpp b/libraries/AP_Terrain/TerrainGCS.cpp index 9639a3a382..c9b78669fb 100644 --- a/libraries/AP_Terrain/TerrainGCS.cpp +++ b/libraries/AP_Terrain/TerrainGCS.cpp @@ -204,10 +204,14 @@ void AP_Terrain::send_terrain_report(mavlink_channel_t chan, const Location &loc get_statistics(pending, loaded); float current_height; - if (current_loc.flags.relative_alt) { - current_height = current_loc.alt*0.01f; + if (spacing == 0) { + current_height = 0; } else { - current_height = (current_loc.alt - ahrs.get_home().alt)*0.01f; + if (current_loc.flags.relative_alt) { + current_height = current_loc.alt*0.01f; + } else { + current_height = (current_loc.alt - ahrs.get_home().alt)*0.01f; + } } current_height += home_terrain_height - terrain_height;