← All tools

Message & Error Explainer

What an ArduPilot message means and what to do about it

Українська

The Lua scripts do not have enough memory

WarningBoard, internal errors, CAN, scripting

What ArduPilot says:

All scripts share one block of memory of SCR_HEAP_SIZE bytes (by default 43 KB, 100 KB or 200 KB, by the size of the board). “Insufficent memory loading FILE”: that script did not fit and is not running. “Unable to allocate a heap” and “Couldn't allocate a lua state”: the block itself could not be had, so no script runs. “Required SCR_HEAP_SIZE over N”: while armed, a script needed more than the block holds, and ArduPilot lent it memory from the board's free memory to keep it alive; N is the total it has reached. That warning then blocks the next arming.

What to do, most likely first

  1. SCR_HEAP_SIZE is too small for the scripts you run.

    CheckSet SCR_DEBUG_OPTS bit 1 for a while: after every run of a script a line “Lua: Time: … Mem: …” shows the memory in use.

    FixRaise SCR_HEAP_SIZE well above the N of the message (half as much again is a fair start) and reboot. Clear the debug bit afterwards.

  2. The board has less free memory than SCR_HEAP_SIZE asks for.

    Check“Unable to allocate a heap” right at start-up; the ground station shows the free memory.

    FixRun fewer or smaller scripts, switch off features you do not use, and set SCR_HEAP_SIZE to what really is free.

  3. A script keeps taking memory and never gives it back.

    CheckWith the debug bit set, the first Mem number grows run after run.

    FixCorrect the script: tables that only grow are the usual reason.

Memory is lent only while armed, and only while at least 20 KB of the board's memory stays free. On the ground, disarmed, the script that asks for too much stops with an error instead.

Parameters to look at

ParameterWhat it is
SCR_HEAP_SIZEScripting Heap Size
SCR_DEBUG_OPTSScripting Debug Level
SCR_ENABLEEnable Scripting
The code that sends it

Insufficent memory loading …

libraries/AP_Scripting/lua_scripts.cpp lua_scripts::load_script() · Open in ArduPilot Copter-4.7.1

Lua: Unable to allocate a heap

libraries/AP_Scripting/lua_scripts.cpp lua_scripts::run() · Open in ArduPilot Copter-4.7.1

Lua: Couldn't allocate a lua state

libraries/AP_Scripting/lua_scripts.cpp lua_scripts::run() · Open in ArduPilot Copter-4.7.1

Required SCR_HEAP_SIZE over N

libraries/AP_Scripting/lua_scripts.cpp lua_scripts::run() · Open in ArduPilot Copter-4.6.3

libraries/AP_Scripting/lua_scripts.cpp lua_scripts::run_engine() · Open in ArduPilot Copter-4.7.1

Written here for Copter 4.6. In the tool you choose your vehicle and version, see your own parameter values beside the ones named here, and drop a flight log to have every message in it explained.

Open it in the Message & Error Explainer