Skip to content

Commit 45f449f

Browse files
committed
AP_Scripting: fix OSD example availability check
The OSD binding exists when OSD_ENABLED is true, but the underlying backend may be nullptr at runtime (e.g., when SITL is not built with SFML support). The simple "if not osd" check only verifies the binding exists, not whether the backend is valid. Add a pcall-based check that tests if a method call succeeds, which properly detects when the backend is unavailable.
1 parent 3dea8a0 commit 45f449f

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

  • libraries/AP_Scripting/examples

libraries/AP_Scripting/examples/osd.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,21 @@ end
131131
------------------------------------------------------------
132132
-- Check OSD availability
133133
------------------------------------------------------------
134-
-- The osd binding returns nil if no OSD backend is available
134+
-- The osd binding exists but may have no backend available at runtime
135135
-- (e.g., when SITL is not built with --enable-sfml --sitl-osd)
136+
-- We test availability by attempting a method call with pcall
136137
if not osd then
137138
gcs:send_text(6, "OSD example: osd not available")
138139
return
139140
end
140141

142+
-- Test if the OSD backend is actually available by calling a method
143+
local osd_available = pcall(function() return osd:get_screen() end)
144+
if not osd_available then
145+
gcs:send_text(6, "OSD example: osd not available")
146+
return
147+
end
148+
141149
------------------------------------------------------------
142150
-- Main update function
143151
------------------------------------------------------------

0 commit comments

Comments
 (0)