Skip to content

Conversation

@alxbilger
Copy link
Contributor

Consider the following Python script:

# Required import for SOFA within python
import Sofa

# Import the GUI package
import SofaImGui
import Sofa.Gui

def main():
    # Call the SOFA function to create the root node
    root = Sofa.Core.Node("root")

    # Call the createScene function, as runSofa does
    createScene(root)

    # Once defined, initialization of the scene graph
    Sofa.Simulation.initRoot(root)

    # Launch the GUI (imgui is now by default, to use Qt please refer to the example "basic-useQtGui.py")
    Sofa.Gui.GUIManager.Init("myscene", "imgui")
    Sofa.Gui.GUIManager.createGUI(root, __file__)
    Sofa.Gui.GUIManager.SetDimension(1080, 800)

    # Initialization of the scene will be done here
    Sofa.Gui.GUIManager.MainLoop(root)
    Sofa.Gui.GUIManager.closeGUI()

def createScene(rootNode):
    #Doesn't do anything yet
    return rootNode

if __name__ == '__main__':
    # Note the 2 calls to main()
    main()
    main()

In the same program, we open twice a new GUI. After closing the first GUI, the static pointer to a GUI is dangling. It must be reinitialized to nullptr for a proper behavior (otherwise it crashes).


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@alxbilger alxbilger added pr: fix Fix a bug pr: fast merge Minor change that can be merged without waiting for the 7 review days pr: status to review To notify reviewers to review this pull-request pr: backport todo This PR will be backported into the release preceeding its milestone. labels Jan 8, 2026
@epernod epernod added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status to review To notify reviewers to review this pull-request labels Jan 8, 2026
@bakpaul
Copy link
Contributor

bakpaul commented Jan 8, 2026

Don't we also need to delete the pointer ? Otherwise we have memory leak

@alxbilger
Copy link
Contributor Author

No, it's not the responsibility of GUIManager. Each GUI destroys itself

@hugtalbot hugtalbot merged commit 364c09b into sofa-framework:master Jan 9, 2026
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: backport todo This PR will be backported into the release preceeding its milestone. pr: fast merge Minor change that can be merged without waiting for the 7 review days pr: fix Fix a bug pr: status ready Approved a pull-request, ready to be squashed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants