瀏覽代碼

Fix stack overflow in Perlin noise generator.

legacy
Sam Hocevar 6 年之前
父節點
當前提交
54b32b19d1
共有 1 個檔案被更改,包括 5 行新增1 行删除
  1. +5
    -1
      src/lol/math/noise/perlin.h

+ 5
- 1
src/lol/math/noise/perlin.h 查看文件

@@ -65,11 +65,15 @@ public:

/* Compute all gradient contributions, for each of the 2^N corners
* of the hypercube. */
for (int i = 0; i < (1 << N); ++i)
for (int i = 0; ; ++i)
{
/* Accumulate Perlin noise */
ret += multiplier * dot(delta, this->get_gradient(origin));

/* Avoid buffer overflow below in origin[bit] */
if (i + 1 == (1 << N))
break;

/* Don’t use the binary pattern for “i” but use its Gray code
* “j” instead, so we know we only have one component to alter
* in “origin” and in “delta”. We know which bit was flipped by


Loading…
取消
儲存