Skip to content

SofaPython3 import leads to segfault - #141

Merged
hugtalbot merged 1 commit into
SofaDefrost:masterfrom
p-shg:sofapython3_segfault_fix
Oct 16, 2026
Merged

hugtalbot merged 1 commit into
SofaDefrost:masterfrom
p-shg:sofapython3_segfault_fix

Conversation

@p-shg

@p-shg p-shg commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

When a scene is created from a Python script (import Sofa, e.g. Gym-style environments, tests, batch simulations), the scene initializes and animates correctly but the process segfaults when Python exits (exit code 139).
Loading SofaPython3 through the PluginManager (RequiredPlugin or SofaRuntime.importPlugin("SofaPython3")) seems to trigger it.
A scene with no RequiredPlugin on SofaPython3 exits cleanly.

Loading SofaPython3 manually seems to be never needed:

  • runSofa already loads SofaPython3 when reading .py scene
  • python already loads through import Sofa

Loading SofaPython3 twice through the PluginManager may need to raise a warning or error in SofaPython3

MainHeader, Scene.addMainHeader and Settings always appended
"SofaPython3" to the plugins list. When a scene is built from a Python
script (import Sofa) and not from runSofa, this RequiredPlugin loads
libSofaPython3.so a second time through the PluginManager, and the
process segfaults at interpreter exit.
@p-shg
p-shg requested review from bakpaul and damienmarchal October 9, 2026 14:57
@p-shg

p-shg commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

I also use Black formatter which may have triggered more changes in the files than strictly necessary, let me know if I should set different arguments to the formatter
I do believe the indentation was wrong/confusing though

@hugtalbot hugtalbot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for your contribution @p-shg
The change of indentation made it hard to compare in the GitHub GUI but I see you only changed ' in to " and removed the autoload of SofaPython3

Thanks for this fix.
FYI we are currently working on a new design of prefabs. We will keep you posted!

By the way, do not hesitate to join us next month in Lille: https://www.sofa-framework.org/sofa-events/sofa-week-2026/

@hugtalbot
hugtalbot merged commit 75f24c4 into SofaDefrost:master Oct 16, 2026
3 of 4 checks passed
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.

2 participants