mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-10 18:08:30 -04:00
AP_Scripting: add init failure check
This commit is contained in:
parent
121accf392
commit
f2bb56bf1e
@ -87,7 +87,7 @@ bool AP_Scripting::init(void) {
|
||||
if (!hal.scheduler->thread_create(FUNCTOR_BIND_MEMBER(&AP_Scripting::thread, void),
|
||||
"Scripting", SCRIPTING_STACK_SIZE, AP_HAL::Scheduler::PRIORITY_SCRIPTING, 0)) {
|
||||
gcs().send_text(MAV_SEVERITY_CRITICAL, "Could not create scripting stack (%d)", SCRIPTING_STACK_SIZE);
|
||||
_enable = 0;
|
||||
_init_failed = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -96,8 +96,9 @@ bool AP_Scripting::init(void) {
|
||||
|
||||
void AP_Scripting::thread(void) {
|
||||
lua_scripts *lua = new lua_scripts(_script_vm_exec_count, _script_heap_size, _debug_level);
|
||||
if (lua == nullptr) {
|
||||
if (lua == nullptr || !lua->heap_allocated()) {
|
||||
gcs().send_text(MAV_SEVERITY_CRITICAL, "Unable to allocate scripting memory");
|
||||
_init_failed = true;
|
||||
return;
|
||||
}
|
||||
lua->run();
|
||||
|
@ -29,6 +29,7 @@ public:
|
||||
AP_Scripting &operator=(const AP_Scripting&) = delete;
|
||||
|
||||
bool init(void);
|
||||
bool init_failed(void) const { return _init_failed; }
|
||||
|
||||
bool enabled(void) const { return _enable != 0; };
|
||||
|
||||
@ -46,6 +47,8 @@ private:
|
||||
AP_Int32 _script_heap_size;
|
||||
AP_Int8 _debug_level;
|
||||
|
||||
bool _init_failed; // true if memory allocation failed
|
||||
|
||||
static AP_Scripting *_singleton;
|
||||
|
||||
};
|
||||
|
@ -30,6 +30,9 @@ public:
|
||||
lua_scripts(const lua_scripts &other) = delete;
|
||||
lua_scripts &operator=(const lua_scripts&) = delete;
|
||||
|
||||
// return true if initialisation failed
|
||||
bool heap_allocated() const { return _heap != nullptr; }
|
||||
|
||||
// run scripts, does not return unless an error occured
|
||||
void run(void);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user