QMatrix4x4: fix aliasing problem in operator*=
When multiplying a QMatrix4x4 by itself, we were clobbering the very matrix we read from. Employ read-caching to avoid this aliasing problem. [ChangeLog][QtGui][QMatrix4x4] operator*=() now calculates the correct result even if the RHS and LHS are the same object. Change-Id: I8534d56cfdd62c336577125127f05173fcec2873 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
This commit is contained in:
parent
98e0cb0a28
commit
5662234afa
@ -423,8 +423,9 @@ inline QMatrix4x4& QMatrix4x4::operator-=(const QMatrix4x4& other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline QMatrix4x4& QMatrix4x4::operator*=(const QMatrix4x4& other)
|
||||
inline QMatrix4x4& QMatrix4x4::operator*=(const QMatrix4x4& o)
|
||||
{
|
||||
const QMatrix4x4 other = o; // prevent aliasing when &o == this ### Qt 6: take o by value
|
||||
flagBits |= other.flagBits;
|
||||
|
||||
if (flagBits < Rotation2D) {
|
||||
|
@ -1227,6 +1227,10 @@ void tst_QMatrixNxN::multiply4x4()
|
||||
QMatrix4x4 m5;
|
||||
m5 = m1 * m2;
|
||||
QVERIFY(isSame(m5, (const float *)m3Values));
|
||||
|
||||
QMatrix4x4 m1xm1 = m1 * m1;
|
||||
m1 *= m1;
|
||||
QCOMPARE(m1, m1xm1);
|
||||
}
|
||||
|
||||
// Test matrix multiplication for 4x3 matrices.
|
||||
|
Loading…
Reference in New Issue
Block a user