]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/YASim/Turbulence.cpp
FGPUIDialog: fix reading from already free'd memory.
[flightgear.git] / src / FDM / YASim / Turbulence.cpp
index da9741f7e1dd0132ab654cc0d5a25241dbf09842..1b4048d1ed31db1ee589df741f149ed63c5912c7 100644 (file)
@@ -138,8 +138,8 @@ void Turbulence::getTurbulence(double* loc, float alt, float* up,
     double b = (loc[1] + _off[1]) + _timeOff;
     a -= _sz * Math::floor(a * (1.0/_sz));
     b -= _sz * Math::floor(b * (1.0/_sz));
-    int x = (int)Math::floor(a);
-    int y = (int)Math::floor(b);
+    int x = ((int)Math::floor(a))&(_sz-1);
+    int y = ((int)Math::floor(b))&(_sz-1);
 
     // Convert to fractional interpolation factors
     a -= x;
@@ -270,12 +270,10 @@ float Turbulence::iturb(unsigned int x, unsigned int y)
         xfrac = xfrac*xfrac*(3 - 2*xfrac); // ... as cubics
         yfrac = yfrac*yfrac*(3 - 2*yfrac);
 
-#define WRAP(a) (a) >= wrapmax ? 0 : (a)
-        float p00 = lattice(WRAP(xl),   WRAP(yl)); // lattice values
-        float p01 = lattice(WRAP(xl),   WRAP(yl+1));
-        float p10 = lattice(WRAP(xl+1), WRAP(yl));
-        float p11 = lattice(WRAP(xl+1), WRAP(yl+1));
-#undef WRAP
+       float p00 = lattice(xl,   yl); // lattice values
+        float p01 = lattice(xl,   yl+1);
+        float p10 = lattice(xl+1, yl);
+        float p11 = lattice(xl+1, yl+1);
 
         float p0 = p00 * (1-yfrac) + p01 * yfrac;
         float p1 = p10 * (1-yfrac) + p11 * yfrac;