Skip to content

Commit 69a634a

Browse files
[SofaPython3/Binding] Do not use the binding cache mecanisme when the data is dirty (Fix sofa issue #2761) (#243)
* [SofaPython3/DataHelper.cpp] update data before accessing its bufferInfo If not done then the generated buffer info can be out-of-sync the data was dirty. The buffer info is extracting the raw memory address of the contained data. If the data array change then the buffer is not valid anymore. Signed-off-by: Damien Marchal <damien.marchal@univ-lille1.fr> * [SofaPython3] Refresh the array cache if the data is not valid anymore. I was convinced that this caching system was gone. It is not so let's avoid it to provide wrong buffer when the data is not valid anymore.
1 parent 603d457 commit 69a634a

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

Plugin/src/SofaPython3/DataHelper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ size_t getSize(BaseData* self)
294294

295295
py::buffer_info toBufferInfo(BaseData& m)
296296
{
297+
scoped_read_access guard(&m);
298+
297299
const AbstractTypeInfo& nfo { *m.getValueTypeInfo() };
298300
auto itemNfo = nfo.BaseType();
299301

@@ -411,7 +413,7 @@ py::array resetArrayFor(BaseData* d)
411413
py::array getPythonArrayFor(BaseData* d)
412414
{
413415
auto& memcache = getObjectCache();
414-
if(memcache.find(d) == memcache.end())
416+
if(d->isDirty() || memcache.find(d) == memcache.end())
415417
{
416418
auto capsule = py::capsule(new Base::SPtr(d->getOwner()));
417419

0 commit comments

Comments
 (0)