From f0da309a4f5da2271ee062950099fec57b1d7144 Mon Sep 17 00:00:00 2001 From: HifiExperiments Date: Thu, 6 Jun 2024 12:41:18 -0700 Subject: [PATCH 1/3] fix more warnings --- .../model-serializers/src/GLTFSerializer.cpp | 42 ++++++++++++------- .../model-serializers/src/GLTFSerializer.h | 14 +------ libraries/render-utils/src/Model.cpp | 23 ++++++---- libraries/render/src/render/FilterTask.cpp | 4 +- libraries/render/src/render/Item.h | 4 +- libraries/script-engine/src/ScriptManager.cpp | 4 +- .../src/v8/ScriptObjectV8Proxy.cpp | 3 +- libraries/shared/src/BlendshapeConstants.h | 6 +-- 8 files changed, 56 insertions(+), 44 deletions(-) diff --git a/libraries/model-serializers/src/GLTFSerializer.cpp b/libraries/model-serializers/src/GLTFSerializer.cpp index 3896c0577d..1440fb22d2 100644 --- a/libraries/model-serializers/src/GLTFSerializer.cpp +++ b/libraries/model-serializers/src/GLTFSerializer.cpp @@ -30,6 +30,8 @@ #include #include +#include + #include #include @@ -42,6 +44,18 @@ #include "FBXSerializer.h" +float atof_locale_independent(char* str) { + //TODO: Once we have C++17 we can use std::from_chars + std::istringstream streamToParse(str); + streamToParse.imbue(std::locale("C")); + float value; + if (!(streamToParse >> value)) { + qDebug(modelformat) << "cgltf: Cannot parse float from string: " << str; + return 0.0f; + } + return value; +} + #define GLTF_GET_INDICIES(accCount) int index1 = (indices[n + 0] * accCount); int index2 = (indices[n + 1] * accCount); int index3 = (indices[n + 2] * accCount); #define GLTF_APPEND_ARRAY_1(newArray, oldArray) GLTF_GET_INDICIES(1) \ @@ -148,8 +162,8 @@ bool findNodeInPointerArray(const cgltf_node *nodePointer, cgltf_node **nodes, s return false; } -template bool findPointerInArray(const T *pointer, const T *array, size_t arraySize, int &index) { - for (int i = 0; i < arraySize; i++) { +template bool findPointerInArray(const T *pointer, const T *array, size_t arraySize, size_t &index) { + for (size_t i = 0; i < arraySize; i++) { if (&array[i] == pointer) { index = i; return true; @@ -187,13 +201,13 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& auto &node = _data->nodes[index]; for(size_t childIndexInParent = 0; childIndexInParent < node.children_count; childIndexInParent++) { cgltf_node *child = node.children[childIndexInParent]; - int childIndex = 0; + size_t childIndex = 0; if (!findPointerInArray(child, _data->nodes, _data->nodes_count, childIndex)) { qDebug(modelformat) << "findPointerInArray failed for model: " << _url; hfmModel.loadErrorCount++; return false; } - parents[childIndex] = index; + parents[(int)childIndex] = index; } sortedNodes.push_back(index); } @@ -918,14 +932,14 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& continue; } - int jointIndex = 0; + size_t jointIndex = 0; if (!findPointerInArray(node.skin->joints[clusterJoints[c]], _data->nodes, _data->nodes_count, jointIndex)) { qCWarning(modelformat) << "Cannot find the joint " << node.skin->joints[clusterJoints[c]]->name <<" in joint array"; hfmModel.loadErrorCount++; continue; } mesh.clusterIndices[prevMeshClusterIndexCount + c] = - originalToNewNodeIndexMap[jointIndex]; + originalToNewNodeIndexMap[(int)jointIndex]; } // normalize and compress to 16-bits @@ -961,14 +975,14 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& } } - int materialIndex = 0; + size_t materialIndex = 0; if (primitive.material != nullptr && !findPointerInArray(primitive.material, _data->materials, _data->materials_count, materialIndex)) { qCWarning(modelformat) << "GLTFSerializer::buildGeometry: Invalid material pointer"; hfmModel.loadErrorCount++; return false; } if (primitive.material != nullptr) { - part.materialID = materialIDs[materialIndex]; + part.materialID = materialIDs[(int)materialIndex]; } mesh.parts.push_back(part); @@ -1306,7 +1320,7 @@ HFMTexture GLTFSerializer::getHFMTexture(const cgltf_texture *texture) { size_t offset = bufferView->offset; int length = (int)bufferView->size; - int imageIndex = 0; + size_t imageIndex = 0; if (!findPointerInArray(image, _data->images, _data->images_count, imageIndex)) { // This should never happen. It would mean a bug in cgltf library. qDebug(modelformat) << "GLTFSerializer::getHFMTexture: can't find texture in the array"; @@ -1346,7 +1360,7 @@ void GLTFSerializer::setHFMMaterial(HFMMaterial& hfmMat, const cgltf_material& m } if (mToonExtension["shadeMultiplyTexture"].isObject()) { QJsonObject object = mToonExtension["shadeMultiplyTexture"].toObject(); - if (object["index"].isDouble() && object["index"].toInt() < _data->textures_count) { + if (object["index"].isDouble() && object["index"].toInt() < (int)_data->textures_count) { hfmMat.shadeTexture = getHFMTexture(&_data->textures[object["index"].toInt()]); } } @@ -1355,7 +1369,7 @@ void GLTFSerializer::setHFMMaterial(HFMMaterial& hfmMat, const cgltf_material& m } if (mToonExtension["shadingShiftTexture"].isObject()) { QJsonObject object = mToonExtension["shadingShiftTexture"].toObject(); - if (object["index"].isDouble() && object["index"].toInt() < _data->textures_count) { + if (object["index"].isDouble() && object["index"].toInt() < (int)_data->textures_count) { hfmMat.shadingShiftTexture = getHFMTexture(&_data->textures[object["index"].toInt()]); } } @@ -1370,7 +1384,7 @@ void GLTFSerializer::setHFMMaterial(HFMMaterial& hfmMat, const cgltf_material& m } if (mToonExtension["matcapTexture"].isObject()) { QJsonObject object = mToonExtension["matcapTexture"].toObject(); - if (object["index"].isDouble() && object["index"].toInt() < _data->textures_count) { + if (object["index"].isDouble() && object["index"].toInt() < (int)_data->textures_count) { hfmMat.matcapTexture = getHFMTexture(&_data->textures[object["index"].toInt()]); } } @@ -1388,7 +1402,7 @@ void GLTFSerializer::setHFMMaterial(HFMMaterial& hfmMat, const cgltf_material& m } if (mToonExtension["rimMultiplyTexture"].isObject()) { QJsonObject object = mToonExtension["rimMultiplyTexture"].toObject(); - if (object["index"].isDouble() && object["index"].toInt() < _data->textures_count) { + if (object["index"].isDouble() && object["index"].toInt() < (int)_data->textures_count) { hfmMat.rimTexture = getHFMTexture(&_data->textures[object["index"].toInt()]); } } @@ -1417,7 +1431,7 @@ void GLTFSerializer::setHFMMaterial(HFMMaterial& hfmMat, const cgltf_material& m } if (mToonExtension["uvAnimationMaskTexture"].isObject()) { QJsonObject object = mToonExtension["uvAnimationMaskTexture"].toObject(); - if (object["index"].isDouble() && object["index"].toInt() < _data->textures_count) { + if (object["index"].isDouble() && object["index"].toInt() < (int)_data->textures_count) { hfmMat.uvAnimationTexture = getHFMTexture(&_data->textures[object["index"].toInt()]); } } diff --git a/libraries/model-serializers/src/GLTFSerializer.h b/libraries/model-serializers/src/GLTFSerializer.h index 203bae47d5..18b3396c45 100644 --- a/libraries/model-serializers/src/GLTFSerializer.h +++ b/libraries/model-serializers/src/GLTFSerializer.h @@ -14,24 +14,12 @@ #ifndef hifi_GLTFSerializer_h #define hifi_GLTFSerializer_h -#include - #include #include #include #include -static float atof_locale_independent(char *str) { - //TODO: Once we have C++17 we can use std::from_chars - std::istringstream streamToParse(str); - streamToParse.imbue(std::locale("C")); - float value; - if(!(streamToParse >> value)) { - qDebug(modelformat) << "cgltf: Cannot parse float from string: " << str; - return 0.0f; - } - return value; -} +float atof_locale_independent(char* str); #define CGLTF_ATOF(str) atof_locale_independent(str) diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index eabcabc7e5..71947f918a 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -1802,8 +1802,8 @@ public: }; static void packBlendshapeOffsetTo_Pos_F32_3xSN10_Nor_3xSN10_Tan_3xSN10(glm::uvec4& packed, const BlendshapeOffsetUnpacked& unpacked) { - float len = glm::compMax(glm::abs(unpacked.positionOffset)); - glm::vec3 normalizedPos(unpacked.positionOffset); + float len = max(abs(unpacked.positionOffsetX), max(abs(unpacked.positionOffsetY), abs(unpacked.positionOffsetZ))); + glm::vec3 normalizedPos(unpacked.positionOffsetX, unpacked.positionOffsetY, unpacked.positionOffsetZ); if (len > 0.0f) { normalizedPos /= len; } else { @@ -1813,8 +1813,8 @@ static void packBlendshapeOffsetTo_Pos_F32_3xSN10_Nor_3xSN10_Tan_3xSN10(glm::uve packed = glm::uvec4( glm::floatBitsToUint(len), glm_packSnorm3x10_1x2(glm::vec4(normalizedPos, 0.0f)), - glm_packSnorm3x10_1x2(glm::vec4(unpacked.normalOffset, 0.0f)), - glm_packSnorm3x10_1x2(glm::vec4(unpacked.tangentOffset, 0.0f)) + glm_packSnorm3x10_1x2(glm::vec4(unpacked.normalOffsetX, unpacked.normalOffsetY, unpacked.normalOffsetZ, 0.0f)), + glm_packSnorm3x10_1x2(glm::vec4(unpacked.tangentOffsetX, unpacked.tangentOffsetY, unpacked.tangentOffsetZ, 0.0f)) ); } @@ -1922,10 +1922,19 @@ void Blender::run() { int index = blendshape.indices.at(j); auto& currentBlendshapeOffset = unpackedBlendshapeOffsets[index]; - currentBlendshapeOffset.positionOffset += blendshape.vertices.at(j) * vertexCoefficient; - currentBlendshapeOffset.normalOffset += blendshape.normals.at(j) * normalCoefficient; + glm::vec3 blendshapePosition = blendshape.vertices.at(j) * vertexCoefficient; + currentBlendshapeOffset.positionOffsetX += blendshapePosition.x; + currentBlendshapeOffset.positionOffsetY += blendshapePosition.y; + currentBlendshapeOffset.positionOffsetZ += blendshapePosition.z; + glm::vec3 blendshapeNormal = blendshape.normals.at(j) * normalCoefficient; + currentBlendshapeOffset.normalOffsetX += blendshapeNormal.x; + currentBlendshapeOffset.normalOffsetY += blendshapeNormal.y; + currentBlendshapeOffset.normalOffsetZ += blendshapeNormal.z; if (j < blendshape.tangents.size()) { - currentBlendshapeOffset.tangentOffset += blendshape.tangents.at(j) * normalCoefficient; + glm::vec3 blendshapeTangent = blendshape.tangents.at(j) * normalCoefficient; + currentBlendshapeOffset.tangentOffsetX += blendshapeTangent.x; + currentBlendshapeOffset.tangentOffsetY += blendshapeTangent.y; + currentBlendshapeOffset.tangentOffsetZ += blendshapeTangent.z; } } } diff --git a/libraries/render/src/render/FilterTask.cpp b/libraries/render/src/render/FilterTask.cpp index b269f44b41..3771d7f743 100644 --- a/libraries/render/src/render/FilterTask.cpp +++ b/libraries/render/src/render/FilterTask.cpp @@ -139,12 +139,12 @@ void IDsToBounds::run(const RenderContextPointer& renderContext, const ItemIDs& for (auto id : inItems) { auto& item = scene->getItem(id); if (item.exist()) { - outItems.emplace_back(ItemBound{ id, item.getBound(renderContext->args) }); + outItems.emplace_back(ItemBound(id, item.getBound(renderContext->args))); } } } else { for (auto id : inItems) { - outItems.emplace_back(ItemBound{ id }); + outItems.emplace_back(ItemBound(id)); } } } diff --git a/libraries/render/src/render/Item.h b/libraries/render/src/render/Item.h index 25663899d1..a5a4b5e32f 100644 --- a/libraries/render/src/render/Item.h +++ b/libraries/render/src/render/Item.h @@ -339,9 +339,9 @@ class ItemBound { ItemBound(ItemID id) : id(id) { } ItemBound(ItemID id, const AABox& bound) : id(id), bound(bound) { } - ItemID id; + ItemID id { 0 }; AABox bound; - uint32_t padding; + uint32_t padding { 0 }; }; // many Item Bounds in a vector diff --git a/libraries/script-engine/src/ScriptManager.cpp b/libraries/script-engine/src/ScriptManager.cpp index 2caab052ec..26680b10aa 100644 --- a/libraries/script-engine/src/ScriptManager.cpp +++ b/libraries/script-engine/src/ScriptManager.cpp @@ -478,10 +478,10 @@ void ScriptManager::waitTillDoneRunning(bool shutdown) { } } #else - auto startedWaiting = usecTimestampNow(); + //auto startedWaiting = usecTimestampNow(); while (!_isDoneRunning) { // If the final evaluation takes too long, then tell the script engine to stop running - auto elapsedUsecs = usecTimestampNow() - startedWaiting; + //auto elapsedUsecs = usecTimestampNow() - startedWaiting; // TODO: This part was very unsafe and was causing crashes all the time. // I disabled it for now until we find a safer solution. // With it disabled now we get clean shutdowns and restarts. diff --git a/libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp b/libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp index 13b7f6f541..7c3fd07e9b 100644 --- a/libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp +++ b/libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp @@ -1309,7 +1309,8 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu } v8::TryCatch tryCatch(isolate); - callback->Call(functionContext, v8This, numArgs, args); + auto maybeResult = callback->Call(functionContext, v8This, numArgs, args); + Q_UNUSED(maybeResult); // Signals don't have return values if (tryCatch.HasCaught()) { QString errorMessage(QString("Signal proxy ") + fullName() + " connection call failed: \"" + _engine->formatErrorMessageFromTryCatch(tryCatch) diff --git a/libraries/shared/src/BlendshapeConstants.h b/libraries/shared/src/BlendshapeConstants.h index 5dd1f0abbb..596e7df4ee 100644 --- a/libraries/shared/src/BlendshapeConstants.h +++ b/libraries/shared/src/BlendshapeConstants.h @@ -119,9 +119,9 @@ struct BlendshapeOffsetPacked { }; struct BlendshapeOffsetUnpacked { - glm::vec3 positionOffset; - glm::vec3 normalOffset; - glm::vec3 tangentOffset; + float positionOffsetX, positionOffsetY, positionOffsetZ; + float normalOffsetX, normalOffsetY, normalOffsetZ; + float tangentOffsetX, tangentOffsetY, tangentOffsetZ; }; using BlendshapeOffset = BlendshapeOffsetPacked; From 5933627aa76011112d147cbe925b92e02ca2d0f0 Mon Sep 17 00:00:00 2001 From: HifiExperiments Date: Thu, 6 Jun 2024 17:11:10 -0700 Subject: [PATCH 2/3] a few more windows warnings --- libraries/graphics/src/graphics/Geometry.cpp | 2 +- libraries/script-engine/src/v8/FastScriptValueUtils.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/graphics/src/graphics/Geometry.cpp b/libraries/graphics/src/graphics/Geometry.cpp index 3984863f1c..e46097207b 100644 --- a/libraries/graphics/src/graphics/Geometry.cpp +++ b/libraries/graphics/src/graphics/Geometry.cpp @@ -45,7 +45,7 @@ void Mesh::setVertexFormatAndStream(const gpu::Stream::FormatPointer& vf, const // We require meshes to have a color attribute. If they don't, we default to white. if (!_vertexFormat->hasAttribute(gpu::Stream::COLOR)) { - int channelNum = _vertexStream.getNumBuffers(); + gpu::Stream::Slot channelNum = (gpu::Stream::Slot)_vertexStream.getNumBuffers(); _vertexFormat->setAttribute(gpu::Stream::COLOR, channelNum, gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA), 0, gpu::Stream::PER_INSTANCE); _vertexStream.addBuffer(_colorBuffer, 0, _vertexFormat->getChannels().at(channelNum)._stride); } diff --git a/libraries/script-engine/src/v8/FastScriptValueUtils.cpp b/libraries/script-engine/src/v8/FastScriptValueUtils.cpp index d1545e60cb..d45b01b303 100644 --- a/libraries/script-engine/src/v8/FastScriptValueUtils.cpp +++ b/libraries/script-engine/src/v8/FastScriptValueUtils.cpp @@ -56,7 +56,7 @@ bool qBytearrayFromScriptValue(const ScriptValue& object, QByteArray &qByteArray return false; } v8::Local arrayBuffer = v8::Local::Cast(v8Value); - qByteArray.resize(arrayBuffer->ByteLength()); + qByteArray.resize((int)arrayBuffer->ByteLength()); memcpy(qByteArray.data(), arrayBuffer->Data(), arrayBuffer->ByteLength()); return true; } From 93276a901df73e79a180608e3ab6fd5c7d8fde9e Mon Sep 17 00:00:00 2001 From: HifiExperiments Date: Fri, 7 Jun 2024 14:22:02 -0700 Subject: [PATCH 3/3] one more warning --- interface/src/avatar/MyAvatar.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 5d3d6f0d1f..85972058da 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -5768,8 +5768,7 @@ void MyAvatar::FollowHelper::deactivate() { } void MyAvatar::FollowHelper::deactivate(CharacterController::FollowType type) { - int int_type = static_cast(type); - assert(int_type >= 0 && int_type < static_cast(CharacterController::FollowType::Count)); + assert((int)type >= 0 && (int)type < static_cast(CharacterController::FollowType::Count)); _timeRemaining[(int)type] = 0.0f; } @@ -5777,16 +5776,14 @@ void MyAvatar::FollowHelper::deactivate(CharacterController::FollowType type) { // eg. activate(FollowType::Rotation, true) snaps the FollowHelper's rotation immediately // to the rotation of its _followDesiredBodyTransform. void MyAvatar::FollowHelper::activate(CharacterController::FollowType type, const bool snapFollow) { - int int_type = static_cast(type); - assert(int_type >= 0 && int_type < static_cast(CharacterController::FollowType::Count)); + assert((int)type >= 0 && (int)type < static_cast(CharacterController::FollowType::Count)); // TODO: Perhaps, the follow time should be proportional to the displacement. _timeRemaining[(int)type] = snapFollow ? CharacterController::FOLLOW_TIME_IMMEDIATE_SNAP : FOLLOW_TIME; } bool MyAvatar::FollowHelper::isActive(CharacterController::FollowType type) const { - int int_type = static_cast(type); - assert(int_type >= 0 && int_type < static_cast(CharacterController::FollowType::Count)); + assert((int)type >= 0 && (int)type < static_cast(CharacterController::FollowType::Count)); return _timeRemaining[(int)type] > 0.0f; }