Skip to content

Run the solar panel line-of-sight ray cast on the render thread (fixes #44) - #50

Merged
ivanperez-keera merged 1 commit into
space-ros:mainfrom
asimonov:solar_panel_render_thread
Oct 1, 2026
Merged

ivanperez-keera merged 1 commit into
space-ros:mainfrom
asimonov:solar_panel_render_thread

Conversation

@asimonov

@asimonov asimonov commented Sep 4, 2026

Copy link
Copy Markdown
Member

Fixes #44. Stacked on #48 (the first two commits are that PR's; only the last one, "Run the solar panel line-of-sight ray cast on the render thread", is this one) — merge after it.

SolarPanelPlugin created and cast a rendering RayQuery from PostUpdate. Gazebo Harmonic executes ISystemPostUpdate systems on parallel worker threads, so the rover's three panel instances hit the Ogre scene concurrently with each other and with the Sensors system's render thread, corrupting the heap within seconds of spawning (malloc_consolidate(): invalid chunk size → std::bad_alloc, or SIGSEGV / SIGBUS on other runs). Bisecting by disabling one plugin at a time: only disabling this plugin keeps the server alive.

All rendering access now happens in a gz::sim::events::PostRender callback on the render thread; PostUpdate hands the sun-to-panel ray over under a mutex and takes back the latest line-of-sight result. The power computation is unchanged, and the ray query is created once instead of on every simulation step. The same structure runs on Fortress.

Verification

  • Harmonic, Jazzy demo (lunar_pole_exploration_rover: Migrate to ROS 2 Jazzy and Gazebo Harmonic (#164) demos#165) headless: with this change the server runs for the whole test session (drive, rotate, camera sweeps, sensor switching) with no crash output; without it, it dies within seconds of the rover spawning. Solar output 106.786 W at rest, identical to the Fortress reading, rising to ~129 W as the rover turns.
  • Fortress, Humble demo image built from demos main against this branch: server alive, plugins loaded from the image build, solar ~106.7 W, battery 30 V / 100 %.

@ana-GT

ana-GT commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Tested this with demos/PR 165. Seems to work as expected (no longer crashes)

@asimonov asimonov self-assigned this Sep 17, 2026
…e-ros#44).

Gazebo runs ISystemPostUpdate systems on parallel worker threads.
SolarPanelPlugin created a rendering RayQuery and cast it from PostUpdate, so
the three panel instances on the rover hit the Ogre scene concurrently with
each other and with the Sensors system's render thread. Under Harmonic that
corrupts the heap within seconds of the rover spawning (malloc_consolidate,
std::bad_alloc, SIGSEGV or SIGBUS depending on the run). Disabling this one
plugin makes the crash go away; disabling either of the other two does not.

Move all rendering access into a gz::sim::events::PostRender callback, which
runs on the render thread. PostUpdate now only reads the entity state it needs
from the ECM, hands the sun-to-panel ray to the render thread under a mutex,
takes back the latest line-of-sight result and publishes the power output. The
power computation itself is unchanged. The unused static scene event and
SetScene hook are removed, and the ray query is created once instead of on
every simulation step.
@ivanperez-keera
ivanperez-keera force-pushed the solar_panel_render_thread branch from 6b98bf3 to 2b39c3b Compare October 1, 2026 00:46

@ivanperez-keera ivanperez-keera left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved based on check performed by @ana-GT .

@ivanperez-keera
ivanperez-keera merged commit 13226b0 into space-ros:main Oct 1, 2026
1 check passed
@asimonov
asimonov deleted the solar_panel_render_thread branch October 4, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SolarPanelPlugin corrupts the heap on Gazebo Harmonic: rendering from PostUpdate

3 participants