Skip to content

Commit

Permalink
Merge pull request #1007 from HifiExperiments/warnings_master2
Browse files Browse the repository at this point in the history
Fix more warnings
  • Loading branch information
daleglass committed Jun 8, 2024
2 parents 32944d4 + 93276a9 commit 9047d6a
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 52 deletions.
9 changes: 3 additions & 6 deletions interface/src/avatar/MyAvatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5768,25 +5768,22 @@ void MyAvatar::FollowHelper::deactivate() {
}

void MyAvatar::FollowHelper::deactivate(CharacterController::FollowType type) {
int int_type = static_cast<int>(type);
assert(int_type >= 0 && int_type < static_cast<int>(CharacterController::FollowType::Count));
assert((int)type >= 0 && (int)type < static_cast<int>(CharacterController::FollowType::Count));
_timeRemaining[(int)type] = 0.0f;
}

// snapFollow: true to snap immediately to the desired transform with regard to '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<int>(type);
assert(int_type >= 0 && int_type < static_cast<int>(CharacterController::FollowType::Count));
assert((int)type >= 0 && (int)type < static_cast<int>(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<int>(type);
assert(int_type >= 0 && int_type < static_cast<int>(CharacterController::FollowType::Count));
assert((int)type >= 0 && (int)type < static_cast<int>(CharacterController::FollowType::Count));
return _timeRemaining[(int)type] > 0.0f;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/graphics/src/graphics/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
42 changes: 28 additions & 14 deletions libraries/model-serializers/src/GLTFSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <qfile.h>
#include <qfileinfo.h>

#include <sstream>

#include <glm/gtx/transform.hpp>

#include <shared/NsightHelpers.h>
Expand All @@ -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) \
Expand Down Expand Up @@ -148,8 +162,8 @@ bool findNodeInPointerArray(const cgltf_node *nodePointer, cgltf_node **nodes, s
return false;
}

template<typename T> bool findPointerInArray(const T *pointer, const T *array, size_t arraySize, int &index) {
for (int i = 0; i < arraySize; i++) {
template<typename T> 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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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()]);
}
}
Expand All @@ -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()]);
}
}
Expand All @@ -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()]);
}
}
Expand All @@ -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()]);
}
}
Expand Down Expand Up @@ -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()]);
}
}
Expand Down
14 changes: 1 addition & 13 deletions libraries/model-serializers/src/GLTFSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,12 @@
#ifndef hifi_GLTFSerializer_h
#define hifi_GLTFSerializer_h

#include <sstream>

#include <memory.h>
#include <QtNetwork/QNetworkReply>
#include <hfm/ModelFormatLogging.h>
#include <hfm/HFMSerializer.h>

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)

Expand Down
23 changes: 16 additions & 7 deletions libraries/render-utils/src/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,8 +1802,8 @@ class CollisionRenderGeometry : public Geometry {
};

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 {
Expand All @@ -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))
);
}

Expand Down Expand Up @@ -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;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/render/src/render/FilterTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
4 changes: 2 additions & 2 deletions libraries/render/src/render/Item.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions libraries/script-engine/src/ScriptManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion libraries/script-engine/src/v8/FastScriptValueUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool qBytearrayFromScriptValue(const ScriptValue& object, QByteArray &qByteArray
return false;
}
v8::Local<v8::ArrayBuffer> arrayBuffer = v8::Local<v8::ArrayBuffer>::Cast(v8Value);
qByteArray.resize(arrayBuffer->ByteLength());
qByteArray.resize((int)arrayBuffer->ByteLength());
memcpy(qByteArray.data(), arrayBuffer->Data(), arrayBuffer->ByteLength());
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions libraries/shared/src/BlendshapeConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9047d6a

Please sign in to comment.