From 756c4c9e6d51564bc32c99701efd939303ce31ff Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 27 May 2020 13:36:01 +0200 Subject: Avoid truncating in QSGMaterial::compare() implementations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Qt 5.0 pattern of subtracting pointers and returning them is not suitable (on 64-bit archs) since the return type is an int. There is also QSGTexture::comparisonKey() now which is a qint64. Just return -1 and 1 as appropriate. Change-Id: Iaf3377b484a8c4b19b0960f1e8def05e4fa68ce7 Reviewed-by: Christian Strømme --- examples/quick/scenegraph/graph/noisynode.cpp | 6 ++---- examples/quick/scenegraph/twotextureproviders/xorblender.cpp | 11 +++++------ 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'examples/quick') diff --git a/examples/quick/scenegraph/graph/noisynode.cpp b/examples/quick/scenegraph/graph/noisynode.cpp index e85757d426..c39e775e98 100644 --- a/examples/quick/scenegraph/graph/noisynode.cpp +++ b/examples/quick/scenegraph/graph/noisynode.cpp @@ -107,10 +107,8 @@ public: if (!state.texture || !other->state.texture) return state.texture ? 1 : -1; - if (qint64 diff = state.texture->comparisonKey() - other->state.texture->comparisonKey()) - return diff; - - return 0; + const qint64 diff = state.texture->comparisonKey() - other->state.texture->comparisonKey(); + return diff < 0 ? -1 : (diff > 0 ? 1 : 0); } struct { diff --git a/examples/quick/scenegraph/twotextureproviders/xorblender.cpp b/examples/quick/scenegraph/twotextureproviders/xorblender.cpp index 276625d908..9971f202a7 100644 --- a/examples/quick/scenegraph/twotextureproviders/xorblender.cpp +++ b/examples/quick/scenegraph/twotextureproviders/xorblender.cpp @@ -117,13 +117,12 @@ int XorBlendMaterial::compare(const QSGMaterial *o) const if (!state.texture2 || !other->state.texture2) return state.texture2 ? -1 : 1; - if (qint64 diff = state.texture1->comparisonKey() - other->state.texture1->comparisonKey()) - return diff; + qint64 diff = state.texture1->comparisonKey() - other->state.texture1->comparisonKey(); + if (diff != 0) + return diff < 0 ? -1 : 1; - if (qint64 diff = state.texture2->comparisonKey() - other->state.texture2->comparisonKey()) - return diff; - - return 0; + diff = state.texture2->comparisonKey() - other->state.texture2->comparisonKey(); + return diff < 0 ? -1 : (diff > 0 ? 1 : 0); } XorBlendRhiShader::XorBlendRhiShader() -- cgit v1.2.3