Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene creation stops when encounter a warning #92

Closed
EulalieCoevoet opened this issue Jan 19, 2021 · 6 comments · Fixed by #105
Closed

Scene creation stops when encounter a warning #92

EulalieCoevoet opened this issue Jan 19, 2021 · 6 comments · Fixed by #105

Comments

@EulalieCoevoet
Copy link
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.

@jnbrunet
Copy link
Collaborator

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.

@EulalieCoevoet
Copy link
Contributor Author

EulalieCoevoet commented Jan 19, 2021

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.

@jnbrunet
Copy link
Collaborator

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.

@EulalieCoevoet
Copy link
Contributor Author

Yep, that solves it.

@damienmarchal
Copy link
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.

@jnbrunet
Copy link
Collaborator

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants