Skip to content

Commit

Permalink
#5371: Sanity-check the texture projection before running the fit alg…
Browse files Browse the repository at this point in the history
…orithm
  • Loading branch information
codereader committed Nov 15, 2020
1 parent 4e1ec43 commit 69ff32c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions radiantcore/brush/TextureMatrix.cpp
Expand Up @@ -207,3 +207,13 @@ Matrix4 TextureMatrix::getTransform() const {

return transform;
}

bool TextureMatrix::isSane() const
{
return !std::isnan(coords[0][0]) && !std::isinf(coords[0][0]) &&
!std::isnan(coords[0][1]) && !std::isinf(coords[0][1]) &&
!std::isnan(coords[0][2]) && !std::isinf(coords[0][2]) &&
!std::isnan(coords[1][0]) && !std::isinf(coords[1][0]) &&
!std::isnan(coords[1][1]) && !std::isinf(coords[1][1]) &&
!std::isnan(coords[1][2]) && !std::isinf(coords[1][2]);
}
3 changes: 3 additions & 0 deletions radiantcore/brush/TextureMatrix.h
Expand Up @@ -57,6 +57,9 @@ struct TextureMatrix
* components, they are just copied into the right places.
*/
Matrix4 getTransform() const;

// Checks if any of the matrix components are NaN or INF (in which case the matrix is not sane)
bool isSane() const;
};

inline std::ostream& operator<<(std::ostream& st, const TextureMatrix& texdef)
Expand Down
3 changes: 2 additions & 1 deletion radiantcore/brush/TextureProjection.cpp
Expand Up @@ -177,7 +177,8 @@ void TextureProjection::fitTexture(std::size_t width, std::size_t height, const
return;
}

Matrix4 st2tex = getTransform();
// Sanity-check the matrix, if it contains any NaNs or INFs we fall back to the default projection (#5371)
Matrix4 st2tex = matrix.isSane() ? getTransform() : GetDefaultProjection().getTransform();

// the current texture transform
Matrix4 local2tex = st2tex;
Expand Down

0 comments on commit 69ff32c

Please sign in to comment.