From f85ae74ac2faca6eebc34a0f3724616ce27b0e50 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Sat, 5 Nov 2022 00:05:10 +0900 Subject: [PATCH] [Tizen] Fix Svace issue for 64bit Solve some convert from size_t to uint32_t case. Change-Id: Ic7f013742e9d14d58d1b85fdc9c4a9025f368f50 Signed-off-by: Eunki, Hong --- .../public-api/loader/material-definition.cpp | 6 +++--- dali-scene3d/public-api/loader/mesh-definition.cpp | 24 +++++++++++----------- dali-scene3d/public-api/loader/utils.cpp | 15 +++++++++----- dali-scene3d/public-api/loader/utils.h | 2 +- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/dali-scene3d/public-api/loader/material-definition.cpp b/dali-scene3d/public-api/loader/material-definition.cpp index 9becc3a..480da95 100644 --- a/dali-scene3d/public-api/loader/material-definition.cpp +++ b/dali-scene3d/public-api/loader/material-definition.cpp @@ -113,8 +113,8 @@ MaterialDefinition::LoadRaw(const std::string& imagesPath) const const bool hasTransparency = MaskMatch(mFlags, TRANSPARENCY); // Why we add additional count here? - uint32_t numBuffers = mTextureStages.size() + (hasTransparency ? !CheckTextures(ALBEDO) + !CheckTextures(METALLIC | ROUGHNESS) + !CheckTextures(NORMAL) - : !CheckTextures(ALBEDO | METALLIC) + !CheckTextures(NORMAL | ROUGHNESS)); + uint32_t numBuffers = static_cast(mTextureStages.size()) + (hasTransparency ? !CheckTextures(ALBEDO) + !CheckTextures(METALLIC | ROUGHNESS) + !CheckTextures(NORMAL) + : !CheckTextures(ALBEDO | METALLIC) + !CheckTextures(NORMAL | ROUGHNESS)); if(numBuffers == 0) { return raw; @@ -261,7 +261,7 @@ TextureSet MaterialDefinition::Load(const EnvironmentDefinition::Vector& environ } // Assign textures to slots -- starting with 2D ones, then cubemaps, if any. - if(mEnvironmentIdx < environments.size()) + if(mEnvironmentIdx < static_cast(environments.size())) { auto& envTextures = environments[mEnvironmentIdx].second; // If pre-computed brdf texture is defined, set the texture. diff --git a/dali-scene3d/public-api/loader/mesh-definition.cpp b/dali-scene3d/public-api/loader/mesh-definition.cpp index b07d0e2..f147ca7 100644 --- a/dali-scene3d/public-api/loader/mesh-definition.cpp +++ b/dali-scene3d/public-api/loader/mesh-definition.cpp @@ -177,7 +177,7 @@ void GenerateNormals(MeshDefinition::RawData& raw) DALI_ASSERT_DEBUG(attribs.size() > 0); // positions IndexProvider getIndex(raw.mIndices.data()); - const uint32_t numIndices = raw.mIndices.empty() ? attribs[0].mNumElements : raw.mIndices.size(); + const uint32_t numIndices = raw.mIndices.empty() ? attribs[0].mNumElements : static_cast(raw.mIndices.size()); auto* positions = reinterpret_cast(attribs[0].mData.data()); @@ -214,7 +214,7 @@ void GenerateTangentsWithUvs(MeshDefinition::RawData& raw) DALI_ASSERT_DEBUG(attribs.size() > 2); // positions, normals, uvs IndexProvider getIndex(raw.mIndices.data()); - const uint32_t numIndices = raw.mIndices.empty() ? attribs[0].mNumElements : raw.mIndices.size(); + const uint32_t numIndices = raw.mIndices.empty() ? attribs[0].mNumElements : static_cast(raw.mIndices.size()); auto* positions = reinterpret_cast(attribs[0].mData.data()); auto* uvs = reinterpret_cast(attribs[2].mData.data()); @@ -328,7 +328,7 @@ void CalculateGltf2BlendShapes(uint8_t* geometryBuffer, std::ifstream& binFile, std::vector buffer(bufferSize); if(ReadAccessor(blendShape.deltas, binFile, buffer.data())) { - blendShape.deltas.mBlob.ApplyMinMax(bufferSize / sizeof(Vector3), reinterpret_cast(buffer.data())); + blendShape.deltas.mBlob.ApplyMinMax(static_cast(bufferSize / sizeof(Vector3)), reinterpret_cast(buffer.data())); // Calculate the difference with the original mesh. // Find the max distance to normalize the deltas. const Vector3* const deltasBuffer = reinterpret_cast(buffer.data()); @@ -353,7 +353,7 @@ void CalculateGltf2BlendShapes(uint8_t* geometryBuffer, std::ifstream& binFile, std::vector buffer(bufferSize); if(ReadAccessor(blendShape.normals, binFile, buffer.data())) { - blendShape.normals.mBlob.ApplyMinMax(bufferSize / sizeof(Vector3), reinterpret_cast(buffer.data())); + blendShape.normals.mBlob.ApplyMinMax(static_cast(bufferSize / sizeof(Vector3)), reinterpret_cast(buffer.data())); // Calculate the difference with the original mesh, and translate to make all values positive. const Vector3* const deltasBuffer = reinterpret_cast(buffer.data()); @@ -384,7 +384,7 @@ void CalculateGltf2BlendShapes(uint8_t* geometryBuffer, std::ifstream& binFile, std::vector buffer(bufferSize); if(ReadAccessor(blendShape.tangents, binFile, buffer.data())) { - blendShape.tangents.mBlob.ApplyMinMax(bufferSize / sizeof(Vector3), reinterpret_cast(buffer.data())); + blendShape.tangents.mBlob.ApplyMinMax(static_cast(bufferSize / sizeof(Vector3)), reinterpret_cast(buffer.data())); // Calculate the difference with the original mesh, and translate to make all values positive. const Vector3* const deltasBuffer = reinterpret_cast(buffer.data()); @@ -634,7 +634,7 @@ MeshDefinition::LoadRaw(const std::string& modelsPath) ExceptionFlinger(ASSERT_LOCATION) << "Failed to read positions from '" << meshPath << "'."; } - uint32_t numVector3 = bufferSize / sizeof(Vector3); + uint32_t numVector3 = static_cast(bufferSize / sizeof(Vector3)); if(mPositions.mBlob.mMin.size() != 3u || mPositions.mBlob.mMax.size() != 3u) { mPositions.mBlob.ComputeMinMax(3u, numVector3, reinterpret_cast(buffer.data())); @@ -667,7 +667,7 @@ MeshDefinition::LoadRaw(const std::string& modelsPath) ExceptionFlinger(ASSERT_LOCATION) << "Failed to read normals from '" << meshPath << "'."; } - mNormals.mBlob.ApplyMinMax(bufferSize / sizeof(Vector3), reinterpret_cast(buffer.data())); + mNormals.mBlob.ApplyMinMax(static_cast(bufferSize / sizeof(Vector3)), reinterpret_cast(buffer.data())); raw.mAttribs.push_back({"aNormal", Property::VECTOR3, static_cast(bufferSize / sizeof(Vector3)), std::move(buffer)}); } @@ -703,14 +703,14 @@ MeshDefinition::LoadRaw(const std::string& modelsPath) } } - mTexCoords.mBlob.ApplyMinMax(bufferSize / sizeof(Vector2), reinterpret_cast(buffer.data())); + mTexCoords.mBlob.ApplyMinMax(static_cast(bufferSize / sizeof(Vector2)), reinterpret_cast(buffer.data())); raw.mAttribs.push_back({"aTexCoord", Property::VECTOR2, static_cast(uvCount), std::move(buffer)}); } if(mTangents.IsDefined()) { - uint32_t propertySize = (mTangentType == Property::VECTOR4) ? sizeof(Vector4) : sizeof(Vector3); + uint32_t propertySize = static_cast((mTangentType == Property::VECTOR4) ? sizeof(Vector4) : sizeof(Vector3)); DALI_ASSERT_ALWAYS(((mTangents.mBlob.mLength % propertySize == 0) || mTangents.mBlob.mStride >= propertySize) && "Tangents buffer length not a multiple of element size"); @@ -825,7 +825,7 @@ MeshDefinition::LoadRaw(const std::string& modelsPath) if(HasBlendShapes()) { - const uint32_t numberOfVertices = mPositions.mBlob.mLength / sizeof(Vector3); + const uint32_t numberOfVertices = static_cast(mPositions.mBlob.mLength / sizeof(Vector3)); // Calculate the size of one buffer inside the texture. raw.mBlendShapeBufferOffset = numberOfVertices; @@ -836,7 +836,7 @@ MeshDefinition::LoadRaw(const std::string& modelsPath) if(!mBlendShapeHeader.IsDefined()) { - CalculateTextureSize(blendShapesBlob.mLength / sizeof(Vector3), textureWidth, textureHeight); + CalculateTextureSize(static_cast(blendShapesBlob.mLength / sizeof(Vector3)), textureWidth, textureHeight); calculateGltf2BlendShapes = true; } else @@ -860,7 +860,7 @@ MeshDefinition::LoadRaw(const std::string& modelsPath) else { Blob unnormalizeFactorBlob; - unnormalizeFactorBlob.mLength = sizeof(float) * ((BlendShapes::Version::VERSION_2_0 == mBlendShapeVersion) ? 1u : numberOfBlendShapes); + unnormalizeFactorBlob.mLength = static_cast(sizeof(float) * ((BlendShapes::Version::VERSION_2_0 == mBlendShapeVersion) ? 1u : numberOfBlendShapes)); if(blendShapesBlob.IsDefined()) { diff --git a/dali-scene3d/public-api/loader/utils.cpp b/dali-scene3d/public-api/loader/utils.cpp index e4f3596..14b4150 100644 --- a/dali-scene3d/public-api/loader/utils.cpp +++ b/dali-scene3d/public-api/loader/utils.cpp @@ -71,14 +71,19 @@ std::string FormatString(const char* format, ...) va_list vl2; va_copy(vl2, vl); - size_t sizeRequired = vsnprintf(nullptr, 0, format, vl); + std::string result; + int32_t length = vsnprintf(nullptr, 0, format, vl); va_end(vl); - ++sizeRequired; - std::string result(sizeRequired, '\0'); - vsnprintf(&result[0], sizeRequired, format, vl2); + if(length >= 0) + { + size_t sizeRequired = static_cast(length); + ++sizeRequired; + std::string formatString(sizeRequired, '\0'); + vsnprintf(&formatString[0], sizeRequired, format, vl2); + result = formatString; + } va_end(vl2); - return result; } diff --git a/dali-scene3d/public-api/loader/utils.h b/dali-scene3d/public-api/loader/utils.h index 05a2063..3a84f09 100644 --- a/dali-scene3d/public-api/loader/utils.h +++ b/dali-scene3d/public-api/loader/utils.h @@ -94,7 +94,7 @@ DALI_SCENE3D_API std::string FormatString(const char* format, ...); */ DALI_SCENE3D_API constexpr size_t NthBit(size_t n) { - return 1 << n; + return 1u << n; } /* -- 2.7.4