File loading race condition leads to crashes
[Update 2022-05-25: added more details to clarify the race]
- A file loading operation calls the plugins's
load()function called in a new thread
addEmptyObject()is used to create an object to hold the loaded file.
- This emits the
emptyObjectAddedsignal, which is connected to
Now these two things can happen in parallel:
- In the loading thread, file loading (e.g. OM or OVM) occurs
- Other plugins get notified vis
slotObjectUpdatedand can operate on this unfinished object at the same time
PropertyVisPlugin::slotObjectUpdated does cause crashes for me, but likely is not the only problematic plugin.
With OM, this can lead to a crash while properties are loaded from the file with the following order of execution:
- Main thread, propvis'
- File load thread:
OpenMesh::PropertyCreator::create_property(), this invalidates the fprops_begin iterator
- Main thread: The Property iterator is dereferenced -> crash
I attached the output of an ASAN instrumented build that runs into this with detailed backtraces:
How should we go about solving this? Maybe just putting a mutex around mesh access from objects? This would also prevent similar issues when performing mesh processing in a worker thread.