Fix crash when resetting a QShader

shader = QShader() would crash because qAtomicAssign() requires that
the other's d-pointer is non-null. Follows pattern from other usages
in Qt.

Pick-to: 6.2 6.4
Fixes: QTBUG-108121
Change-Id: I57d25a804340839d03f9dadcbd44e956fb259c30
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2022-11-14 10:15:26 +01:00
parent 244daf4cfc
commit 6fa2ee7f4a

View File

@ -241,7 +241,13 @@ QShader::QShader(const QShader &other)
QShader &QShader::operator=(const QShader &other) QShader &QShader::operator=(const QShader &other)
{ {
if (d) { if (d) {
if (other.d) {
qAtomicAssign(d, other.d); qAtomicAssign(d, other.d);
} else {
if (!d->ref.deref())
delete d;
d = nullptr;
}
} else if (other.d) { } else if (other.d) {
other.d->ref.ref(); other.d->ref.ref();
d = other.d; d = other.d;