From 2985dd20f6475e386123d71d5933f4ad8fbd0ea5 Mon Sep 17 00:00:00 2001 From: bakpaul Date: Tue, 21 Apr 2026 15:50:17 +0200 Subject: [PATCH] Acquire gil for the full scope of the lifetime returned matrix --- bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_ForceField.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_ForceField.cpp b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_ForceField.cpp index c3ab5f9c..726fb131 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_ForceField.cpp +++ b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_ForceField.cpp @@ -121,7 +121,6 @@ namespace sofapython3 template py::object ForceField_Trampoline::_addKToMatrix(const MechanicalParams* mparams, int nIndices, int nDofs) { - PythonEnvironment::gil acquire; py::dict mp = py::dict("time"_a=getContext()->getTime(), "mFactor"_a=mparams->mFactor(), @@ -136,6 +135,8 @@ namespace sofapython3 template void ForceField_Trampoline::addKToMatrix(const MechanicalParams* mparams, const MultiMatrixAccessor* dfId) { + PythonEnvironment::gil acquire; + MultiMatrixAccessor::MatrixRef mref = dfId->getMatrix(this->mstate); sofa::linearalgebra::BaseMatrix* mat = mref.matrix;