(core): BufferObject are still locked after shallowCopy of Image
Summary
In some cases a BufferObject is still locked after performing a shallowCopy of images. In debug an assert is triggered when the orphan BufferObject is destroyed.
Steps to reproduce
The way I've discovered it
- In debug mode
- Launch sightcalibrator
- Choose a video file
- Assert !
It is caused by SDistorsion code.
We can detail the behaviour following this pseudo-code from SDistorsion:
void updating()
{
// Lock input
const auto inputImage = m_image.lock();
SIGHT_ASSERT("No '" << s_IMAGE_INPUT << "' found.", inputImage);
if(...)
{
// Do something
}
else
{
// Lock output (AND input is still locked)
auto outputImage = m_output.lock();
SIGHT_ASSERT("No '" << s_IMAGE_INOUT << "' found.", outputImage);
if(inputImage && outputImage)
{
outputImage->shallowCopy(inputImage.get_shared());
// Here the original BufferObject of outputImage will be deleted,
// since we point now to the BufferObject of inputImage, but it is still locked !
}
}// crash because original bufferObject of output is still locked
}
Relevant logs and/or screenshots
[3797][00:00:05.751798][fatal] [sight/libs/core/core/memory/BufferManager.cpp:100] Assertion 'm_bufferInfos[bufferPtr].lockCounter.expired()' failed: There are still 1 locks on this BufferObject (0x55593d29fcd0)
Possible fixes
Ugly hack, declare a BufferObject::sptr before locking Images, assign it to the original BufferObject just before the shallowCopy, and it works, since we delay the destruction of this object.
We can also remove the assert, I don't think it is very critical to have this behavior, but may be it is!