AP_OSD: take semaphore in OSD thread for scripting override

The scripting bindings took get_semaphore() around every OSD call, but the
OSD thread updated the display without it, so a scripting draw could run
concurrently with the OSD thread and the lock protected nothing.

Hold the semaphore in the OSD thread around the override check and
update_osd(), and set scripting_override under it, so the OSD thread and
scripting draws are mutually exclusive.
This commit is contained in:
Andy Piper
2026-07-24 11:22:29 +01:00
parent 0a5356ff36
commit 32a139d534
2 changed files with 8 additions and 2 deletions
+5 -2
View File
@@ -409,10 +409,11 @@ void AP_OSD::osd_thread()
update_current_screen();
}
#if AP_SCRIPTING_ENABLED
// hold the semaphore so scripting cannot draw to the OSD while the
// OSD thread is updating it, and vice versa
WITH_SEMAPHORE(_sem);
if (!scripting_override) {
#endif
update_osd();
#if AP_SCRIPTING_ENABLED
} else {
override_count++;
if (override_count > 20) {
@@ -421,6 +422,8 @@ void AP_OSD::osd_thread()
override_count = 0;
}
}
#else
update_osd();
#endif // AP_SCRIPTING_ENABLED
}
}
+3
View File
@@ -659,6 +659,9 @@ public:
}
#if AP_SCRIPTING_ENABLED
AP_OSD_Backend *scripting_get_backend() {
// set the override under the semaphore so the OSD thread sees a
// consistent value; the scripting binding takes it again for the call
WITH_SEMAPHORE(_sem);
scripting_override = true;
override_count = 0;
return _backends[0];