Math: Set matrix to zero when inversion fails

Avoids usage of uninitialized memory when inversion fails.

That uninitialized memory can cause object to become visible when
it is supposed not to or other artifacts like that.

Longer term solution would be to check every instance of invert_m#
function and to explicit fallback when needed (possibly, using
extra utility functions).
This commit is contained in:
Sergey Sharybin 2018-06-22 11:22:50 +02:00
parent f3501a00e2
commit 9921e10583
1 changed files with 3 additions and 0 deletions

View File

@ -48,6 +48,9 @@ bool EIG_invert_m4_m4(float inverse[4][4], const float matrix[4][4])
Matrix4f R;
bool invertible = true;
M.computeInverseWithCheck(R, invertible, 0.0f);
if (!invertible) {
R = R.Zero();
}
memcpy(inverse, R.data(), sizeof(float)*4*4);
return invertible;
}