[Bf-committers] Help with a threading issue

Sean Loh sean.loh at vpac-innovations.com.au
Wed Aug 19 03:19:37 CEST 2015


Hi all,

I'm looking for some help with a threading issue. I'm working on the
classical SPH code in Blender 2.73 and I'm implementing an adaptive
resolution method that is coded in a very similar manner to effectors.
Basically, I tag objects as "Refiners", compute how far away a particle is
and decide whether, or how, to split the particle based on that distance.
I've implemented the tagging of objects, their organisation into a linked
list and the computation of minimum distance to the Refiner using the
objects' BVHTree in pretty much the same way as these functions are coded
for effectors.

The issue I am having is that it only works when Blender is run on a single
thread (-t 1). When I run with multi-threading I get seg faults on random
frames. After a bit of debugging, I figured out the cause of the issue was
that when my code tries to compute the nearest point on the Refiner object
to a particle by calling closest_point_on_surface() in
blender/source/blender/blenkernel/intern/effect.c, something running on
another thread had deleted the BVHTree stored in the Refiner objects'
SurfaceModifierData object. I tried to work around this by adding code to
rebuild the BVHTree before computing the nearest point but the same
function on another thread appears to have also deleted the objects'
derivedFinal, so this also failed. In the end my temporary solution is to
use a busy-waiting process to pause until the derivedFinal exists before
building the BVHTree.

Here's some links to the branch I'm working on and to the function where I
attempt to resolve the issue by rebuilding the BVHTree after the
busy-waiting:

https://github.com/vpac-innovations/blender/tree/feature-sph-adptv-res
https://github.com/vpac-innovations/blender/blob/8f201e9f012fd3ef9a10245dea59c67a27aa2c64/source/blender/physics/intern/BPH_sph.c#L1263

I'm quite new to developing Blender and have basically been building my
knowledge by working from the classical SPH solver up. I also don't have
any previous experience developing multi-threaded software so at this point
I'm in a bit over my head and I figure it's a good time to ask for help. I
guess my main questions are:

1. Where/why is the BVHTree being deleted?

2. How is this issue avoided in effectors since I haven't been able to
reproduce the error by making the object an effector rather than a Refiner?

Thanks in advance

Sean


More information about the Bf-committers mailing list