[Bf-blender-cvs] [e3858f47166] master: Fluid: Updated APIC plugin

Sebastián Barschkis noreply at git.blender.org
Tue Nov 3 19:34:42 CET 2020


Commit: e3858f47166f3eca4837fbc9b2580348fbeec0cb
Author: Sebastián Barschkis
Date:   Tue Nov 3 19:30:46 2020 +0100
Branches: master
https://developer.blender.org/rBe3858f47166f3eca4837fbc9b2580348fbeec0cb

Fluid: Updated APIC plugin

Updated version of APIC plugin in order to resolve ASAN issues.

===================================================================

M	extern/mantaflow/preprocessed/plugin/apic.cpp

===================================================================

diff --git a/extern/mantaflow/preprocessed/plugin/apic.cpp b/extern/mantaflow/preprocessed/plugin/apic.cpp
index 460c6459916..0312544c56b 100644
--- a/extern/mantaflow/preprocessed/plugin/apic.cpp
+++ b/extern/mantaflow/preprocessed/plugin/apic.cpp
@@ -30,7 +30,9 @@ static inline IndexInt indexUFace(const Vec3 &pos, const MACGrid &ref)
 {
   const Vec3i f = toVec3i(pos), c = toVec3i(pos - 0.5);
   const IndexInt index = f.x * ref.getStrideX() + c.y * ref.getStrideY() + c.z * ref.getStrideZ();
-  assertDeb(ref.isInBounds(index), "Grid index out of bounds");
+  assertDeb(ref.isInBounds(index),
+            "U face index out of bounds for particle position [" << pos.x << ", " << pos.y << ", "
+                                                                 << pos.z << "]");
   return (ref.isInBounds(index)) ? index : -1;
 }
 
@@ -38,7 +40,9 @@ static inline IndexInt indexVFace(const Vec3 &pos, const MACGrid &ref)
 {
   const Vec3i f = toVec3i(pos), c = toVec3i(pos - 0.5);
   const IndexInt index = c.x * ref.getStrideX() + f.y * ref.getStrideY() + c.z * ref.getStrideZ();
-  assertDeb(ref.isInBounds(index), "Grid index out of bounds");
+  assertDeb(ref.isInBounds(index),
+            "V face index out of bounds for particle position [" << pos.x << ", " << pos.y << ", "
+                                                                 << pos.z << "]");
   return (ref.isInBounds(index)) ? index : -1;
 }
 
@@ -46,7 +50,9 @@ static inline IndexInt indexWFace(const Vec3 &pos, const MACGrid &ref)
 {
   const Vec3i f = toVec3i(pos), c = toVec3i(pos - 0.5);
   const IndexInt index = c.x * ref.getStrideX() + c.y * ref.getStrideY() + f.z * ref.getStrideZ();
-  assertDeb(ref.isInBounds(index), "Grid index out of bounds");
+  assertDeb(ref.isInBounds(index),
+            "W face index out of bounds for particle position [" << pos.x << ", " << pos.y << ", "
+                                                                 << pos.z << "]");
   return (ref.isInBounds(index)) ? index : -1;
 }
 
@@ -57,7 +63,7 @@ static inline IndexInt indexOffset(
   const IndexInt dY[2] = {0, ref.getStrideY()};
   const IndexInt dZ[2] = {0, ref.getStrideZ()};
   const IndexInt index = gidx + dX[i] + dY[j] + dZ[k];
-  assertDeb(ref.isInBounds(index), "Grid index out of bounds");
+  assertDeb(ref.isInBounds(index), "Offset index " << index << " is out of bounds");
   return (ref.isInBounds(index)) ? index : -1;
 }
 
@@ -271,18 +277,18 @@ void apicMapPartsToMAC(const FlagGrid &flags,
                        const int boundaryWidth = 0)
 {
   // affine map: let's assume that the particle mass is constant, 1.0
-  if (!mass) {
-    MACGrid tmpmass(vel.getParent());
-    mass = &tmpmass;
-  }
+  MACGrid tmpmass(vel.getParent());
 
-  mass->clear();
+  tmpmass.clear();
   vel.clear();
 
   knApicMapLinearVec3ToMACGrid(
-      parts, *mass, vel, partVel, cpx, cpy, cpz, ptype, exclude, boundaryWidth);
-  mass->stomp(VECTOR_EPSILON);
-  vel.safeDivide(*mass);
+      parts, tmpmass, vel, partVel, cpx, cpy, cpz, ptype, exclude, boundaryWidth);
+  tmpmass.stomp(VECTOR_EPSILON);
+  vel.safeDivide(tmpmass);
+
+  if (mass)
+    (*mass).swap(tmpmass);
 }
 static PyObject *_W_0(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
 {



More information about the Bf-blender-cvs mailing list