Skip to content

Commit

Permalink
TS: Fix wrap_periodic_sharedborder to protect better against % by 0 (…
Browse files Browse the repository at this point in the history
…2121)
  • Loading branch information
lgritz committed Jan 11, 2019
1 parent 4f23c85 commit 8421ef8
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/libtexture/texturesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,12 @@ TextureSystemImpl::wrap_periodic_sharedborder(int& coord, int origin, int width)
// Like periodic, but knowing that the first column and last are
// actually the same position, so we essentially skip the last
// column in the next cycle.
if (width <= 2) {
coord = origin; // special case -- just 1 pixel wide
} else {
coord -= origin;
coord %= (width - 1);
if (coord < 0) // Fix negative values
coord += width;
coord += origin;
}
width = std::max(width, 2); // avoid %0 for width=1
coord -= origin;
coord = safe_mod(coord, width - 1);
if (coord < 0) // Fix negative values
coord += width;
coord += origin;
return true;
}

Expand Down Expand Up @@ -290,11 +287,9 @@ wrap_periodic_sharedborder_simd(simd::vint4& coord_, const simd::vint4& origin,
// column in the next cycle.
simd::vint4 coord(coord_);
coord = coord - origin;
coord = coord % (width - 1);
coord = safe_mod(coord, (width - 1));
coord += blend(simd::vint4(origin), width + origin,
coord < 0); // Fix negative values
coord = blend(coord, origin,
width <= 2); // special case -- just 1 pixel wide
coord_ = coord;
return true;
}
Expand Down

0 comments on commit 8421ef8

Please sign in to comment.