diff --git a/libraries/AP_Scripting/lua_scripts.cpp b/libraries/AP_Scripting/lua_scripts.cpp index 6710f328a2..b635d1d4df 100644 --- a/libraries/AP_Scripting/lua_scripts.cpp +++ b/libraries/AP_Scripting/lua_scripts.cpp @@ -540,6 +540,8 @@ void lua_scripts::run(void) { succeeded_initial_load = true; #endif // __clang_analyzer__ + uint32_t expansion_size = 0; + while (AP_Scripting::get_singleton()->should_run()) { #if defined(AP_SCRIPTING_CHECKS) && AP_SCRIPTING_CHECKS >= 1 if (lua_gettop(L) != 0) { @@ -607,6 +609,17 @@ void lua_scripts::run(void) { hal.scheduler->delay(1000); } + /* + report a warning if SCR_HEAP_SIZE wasn't adequate and we + expanded at runtime, so the user can fix it for future + flights + */ + const uint32_t new_expansion_size = _heap.get_expansion_size(); + if (new_expansion_size > expansion_size) { + expansion_size = new_expansion_size; + set_and_print_new_error_message(MAV_SEVERITY_WARNING, "Required SCR_HEAP_SIZE over %u", unsigned(expansion_size)); + } + // re-print the latest error message every 10 seconds 10 times const uint8_t error_prints = 10; if ((print_error_count < error_prints) && (AP_HAL::millis() - last_print_ms > 10000)) {