diff --git a/ArduPlane/config.h b/ArduPlane/config.h index 599a534c83..97e848afa4 100644 --- a/ArduPlane/config.h +++ b/ArduPlane/config.h @@ -420,11 +420,7 @@ // use this to disable geo-fencing #ifndef GEOFENCE_ENABLED -#if HAL_CPU_CLASS > HAL_CPU_CLASS_16 # define GEOFENCE_ENABLED ENABLED -#else - # define GEOFENCE_ENABLED DISABLE -#endif #endif // pwm value on FENCE_CHANNEL to use to enable fenced mode diff --git a/ArduPlane/geofence.cpp b/ArduPlane/geofence.cpp index 23f2b11199..60db9fb456 100644 --- a/ArduPlane/geofence.cpp +++ b/ArduPlane/geofence.cpp @@ -94,7 +94,8 @@ void Plane::geofence_load(void) uint8_t i; if (geofence_state == NULL) { - if (hal.util->available_memory() < 512 + sizeof(struct GeofenceState)) { + uint16_t boundary_size = sizeof(Vector2l) * max_fencepoints(); + if (hal.util->available_memory() < 100 + boundary_size + sizeof(struct GeofenceState)) { // too risky to enable as we could run out of stack goto failed; } @@ -104,7 +105,7 @@ void Plane::geofence_load(void) goto failed; } - geofence_state->boundary = (Vector2l *)calloc(sizeof(Vector2l), max_fencepoints()); + geofence_state->boundary = (Vector2l *)calloc(1, boundary_size); if (geofence_state->boundary == NULL) { free(geofence_state); geofence_state = NULL;