Skip to content

Commit 003c39d

Browse files
committed
fix array out of bounds on c++
1 parent 54055d4 commit 003c39d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

include/nbl/builtin/hlsl/math/linalg/transform.hlsl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace math
1717
namespace linalg
1818
{
1919

20-
/// Builds a rotation 4 * 4 matrix created from an axis vector and an angle.
20+
/// Builds a rotation 3 * 3 matrix created from an axis vector and an angle.
2121
///
2222
/// @param angle Rotation angle expressed in radians.
2323
/// @param axis Rotation axis, must be normalized.
@@ -53,15 +53,15 @@ namespace impl
5353
template<uint16_t MOut, uint16_t MIn, typename T>
5454
struct zero_expand_helper
5555
{
56-
static vector<T, MOut> __call(vector<T, MIn> inVec)
56+
static vector<T, MOut> __call(const vector<T, MIn> inVec)
5757
{
5858
return vector<T, MOut>(inVec, vector<T, MOut - MIn>(0));
5959
}
6060
};
6161
template<uint16_t M, typename T>
6262
struct zero_expand_helper<M,M,T>
6363
{
64-
static vector<T, M> __call(vector<T, M> inVec)
64+
static vector<T, M> __call(const vector<T, M> inVec)
6565
{
6666
return inVec;
6767
}
@@ -81,10 +81,14 @@ matrix<T, NOut, MOut> promote_affine(const matrix<T, NIn, MIn> inMatrix)
8181

8282
using out_row_t = hlsl::vector<T, MOut>;
8383

84-
for (uint32_t row_i = 0; row_i < NOut; row_i++)
84+
NBL_UNROLL for (uint32_t row_i = 0; row_i < NIn; row_i++)
8585
{
86-
retval[row_i] = hlsl::mix(promote<out_row_t>(0.0), zero_expand<MOut, MIn>(inMatrix[row_i]), row_i < NIn);
87-
if ((row_i >= NIn || row_i >= MIn) && row_i < MOut)
86+
retval[row_i] = zero_expand<MOut, MIn>(inMatrix[row_i]);
87+
}
88+
NBL_UNROLL for (uint32_t row_i = NIn; row_i < NOut; row_i++)
89+
{
90+
retval[row_i] = promote<out_row_t>(0.0);
91+
if (row_i >= MIn && row_i < MOut)
8892
retval[row_i][row_i] = T(1.0);
8993
}
9094
return retval;

0 commit comments

Comments
 (0)