Skip to content

Commit

Permalink
AP_Scripting: added warning on heap expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Nov 17, 2024
1 parent 9041b18 commit 8cb033d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions libraries/AP_Scripting/lua_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 8cb033d

Please sign in to comment.