Skip to content

Scene creation stops when encounter a warning #92

Closed

Description

@EulalieCoevoet

When a warning is raised by Sofa, the creation of the scene stops.

After a discussion with Damien, it seems that SofaPython3 should catch python3's exceptions, the same way it was done in SofaPython plugin.

If I understood correctly it wasn't possible with python 3.8 but it should be with the new release 3.9.

Activity

  1. jnbrunet commented on Jan 19, 2021

    @jnbrunet
    Contributor

    Hey @EulalieCoevoet ,

    I'm not sure I understand your issue. Which warning, the one emitted by msg_warning(...) in SOFA? I'm not seeing the link with exceptions triggered by python.

    Do you have a minimal reproducible example? That would be very useful.

  2. EulalieCoevoet commented on Jan 19, 2021

    @EulalieCoevoet
    ContributorAuthor

    You're right I'm mixing different things, and I've opened this issue a bit too fast. Sorry for that, let's do it again.

    I've noticed that the creation of the scene would stop really often (compared to SofaPython). For instance, if I change a property of a prefab:

    class VisualModel(Sofa.Prefab):
    
        properties = [
            {'name':'rotation',       'type':'Vec3d',  'help':'rotate visual model',       'default':[0.,0.,0.]}
         ]
    
        def __init__(self, *args, **kwargs):
            Sofa.Prefab.__init__(self, *args, **kwargs)
            self.rotation = [0.,0.,0.]
    (...)
    
    createScene(root):
        VisualModel()
    

    This example generates the following warning (which is actually hard to link to the problematic line of code):

    [WARNING] [Prefab_Trampoline(VisualModel)] Prefab instantiated. Check for required prefab parameters to fully populate
    

    and the creation of the scene will just stop at this stage. I've had other similar issues, the creation of the scene would just stop without any python error. It's a shame I can't remember/reproduce the other problems I had. I don't think they are all related to this warning in doReInit(), but yeah I'm not sure.

  3. jnbrunet commented on Jan 21, 2021

    @jnbrunet
    Contributor

    Hey @EulalieCoevoet ,

    I just tried your example. While I do get the warning, I'm not having any crash. Are you up-to-date with the master branch of SofaPython3? We fixed many bugs related to inheriting C++ classes in Python recently.

    The warning seems to happen because Prefab::init() calls the Prefab::reinit() (1) before setting its "m_is_initialized" member to true (2):

    void Prefab::init()
    {
        reinit();  // <--------------- (1)
        Inherit1::init(sofa::core::ExecParams::defaultInstance());
        m_is_initialized = true; // <--------------- (2)
    }

    Prefab::reinit() will call the trampoline doReInit function, which emits a warning if "m_is_initialized" is false...

    Could you try changing the order of the calls (1) and (2) like this:

    void Prefab::init()
    {
        Inherit1::init(sofa::core::ExecParams::defaultInstance());
        m_is_initialized = true; // <--------------- (2)
        reinit();  // <--------------- (1)
    }

    I never used the Prefab so I'm not sure of the impact here, although looking very quickly through this part of the code, it doesn't seems too dangerous.

  4. EulalieCoevoet commented on Jan 25, 2021

    @EulalieCoevoet
    ContributorAuthor

    Yep, that solves it.

  5. damienmarchal commented on Jan 26, 2021

    @damienmarchal
    Contributor

    When a warning is raised by Sofa, the creation of the scene stops.

    After a discussion with Damien, it seems that SofaPython3 should catch python3's exceptions, the same way it was done in SofaPython plugin.

    If I understood correctly it wasn't possible with python 3.8 but it should be with the new release 3.9.

    I think there is two issue mixed together.
    One is about the exception risen from python. In SofaPython they were catched by a dedicated hook installed by Sofa in the python interpreter. Because of multithreading this feature was broken before 3.8 and thus SofPython3 was not using it. The consequence is that when there is an error at the python level the behavior is different.

    The other is the error message relative to prefab. @jnbrunet gave a proper answer here.

  6. jnbrunet commented on Jan 26, 2021

    @jnbrunet
    Contributor

    All right, yeah I remember vaguely about this. I created #106 in order to follow the former issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions