diff --git a/libraries/AP_Terrain/AP_Terrain.cpp b/libraries/AP_Terrain/AP_Terrain.cpp index 4ef7a537f1..50c67749fd 100644 --- a/libraries/AP_Terrain/AP_Terrain.cpp +++ b/libraries/AP_Terrain/AP_Terrain.cpp @@ -376,7 +376,7 @@ void AP_Terrain::log_terrain_data() */ bool AP_Terrain::allocate(void) { - if (enable == 0) { + if (enable == 0 || memory_alloc_failed) { return false; } if (cache != nullptr) { @@ -384,13 +384,11 @@ bool AP_Terrain::allocate(void) } cache = (struct grid_cache *)calloc(TERRAIN_GRID_BLOCK_CACHE_SIZE, sizeof(cache[0])); if (cache == nullptr) { - enable.set(0); gcs().send_text(MAV_SEVERITY_CRITICAL, "Terrain: Allocation failed"); memory_alloc_failed = true; return false; } cache_size = TERRAIN_GRID_BLOCK_CACHE_SIZE; - memory_alloc_failed = false; return true; }