SofaPython3
SofaPython3 copied to clipboard
[Binding/Sofa.Core] Call init() by default when creating a python object
The default behavior should be the most common use case while more rare scenario should be accessible but with explicit call api (opt-in vs opt-out strategy).
Currently the default case is:
m = r.addObject("MechanicalObject", position=[1,2,3])
m.init()
l.rest_position() ## Rest position is created from position at init
This is a bit weird as one may expect that once "created" in python the object is immediately accessible in an inited state (not doing so imply user to call init() at every lines).
After the PR the default case become:
m = r.addObject("MechanicalObject", position=[1,2,3])
l.rest_position()
But for rare use case where it makes sense the no init behavior can still be done explicitly:
m = r.addObject("MechanicalObject", position=[1,2,3], __noInit=True)
l.rest_position() # Rest position is "uninited"
m.init() # You can control when you init the object
l.rest_position() #
Unit tests are provided to validate the behavior.
The PR use the Sofa.future module to let users to enable/disable the behavior. By default, the SofaPython behavior is preserved (so no auto-init)
If you want to test you just need to do
from Sofa.Lifetime import __feature__
def createScene(root)
with __feature__("object_auto_init", True):
root.addObject(....)
This PR depends on #184
@AlbanOdot @jnbrunet @RobinEnjalbert what do you think of this auto-init feature? Your input would be valuable to us!
@hugtalbot so as there was no answer it will be time to plan updating and merging ;)
Related to the need for init: https://github.com/sofa-framework/sofa/issues/3012
Reviews taken into account.
However, this scene often crashes with such error:
double free or corruption (out)
########## SIG 6 - SIGABRT: usually caused by an abort() or assert() ##########
I am suspecting the engine TextureInterpolation
@hugtalbot
Thanks for the feedback, can you provide a scene that crash (or elaborate a bit more).
As the risk of incompatibility with some component we don't have time to fix is high this is why this PR rely on the use of #184
with __feature__("autoinit"):
blabblah
the scene here crashes @damienmarchal quite randomly.
What I wrote regarding the init should work fine, shouldn't it?
@hugtalbot Sorry I'm lost, what do you mean by "here" ?
sorry I initially posted in the wrong PR (I was targeting #204) ! sorry for perturbating this one!
To clarify the current situation of this PR, it depends on https://github.com/sofa-framework/SofaPython3/pull/184 which is still in wip. So, let's focus on https://github.com/sofa-framework/SofaPython3/pull/184 to move forward on this one.