From 918589f3204abebd82e02a7747a335ec87ed8ce6 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Wed, 15 Apr 2026 08:26:43 +0900 Subject: [PATCH 1/7] remove various warnings from framework --- .../Helper/src/sofa/helper/system/FileMonitor_macosx.cpp | 2 +- .../src/sofa/linearalgebra/SparseMatrixProduct.inl | 4 ++-- .../Core/src/sofa/simulation/ParallelSparseMatrixProduct.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sofa/framework/Helper/src/sofa/helper/system/FileMonitor_macosx.cpp b/Sofa/framework/Helper/src/sofa/helper/system/FileMonitor_macosx.cpp index 41b884cc94e..ec2808be046 100644 --- a/Sofa/framework/Helper/src/sofa/helper/system/FileMonitor_macosx.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/system/FileMonitor_macosx.cpp @@ -95,7 +95,7 @@ These steps are explained in more detail in the sections that follow. 0.2, // CFTimeInterval latency kFSEventStreamCreateFlagFileEvents // FSEventStreamCreateFlags flags ); - FSEventStreamScheduleWithRunLoop(m_eventStream,CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); + FSEventStreamSetDispatchQueue(m_eventStream, dispatch_get_main_queue()); FSEventStreamStart(m_eventStream); } diff --git a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/SparseMatrixProduct.inl b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/SparseMatrixProduct.inl index 668ab3c26e8..6d7fe261b57 100644 --- a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/SparseMatrixProduct.inl +++ b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/SparseMatrixProduct.inl @@ -291,8 +291,8 @@ void SparseMatrixProduct::computeProductFromIntersection() auto* rhs_ptr = m_rhs->valuePtr(); auto* product_ptr = m_productResult.valuePtr(); - [[maybe_unused]] const auto lhsNonZeros = m_lhs->nonZeros(); - [[maybe_unused]] const auto rhsNonZeros = m_rhs->nonZeros(); + [[maybe_unused]] const Eigen::Index lhsNonZeros = m_lhs->nonZeros(); + [[maybe_unused]] const Eigen::Index rhsNonZeros = m_rhs->nonZeros(); for (const auto& pairs : m_intersectionAB.intersection) { diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/ParallelSparseMatrixProduct.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/ParallelSparseMatrixProduct.h index fcb9a7d4197..5ea7270ab7d 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/ParallelSparseMatrixProduct.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/ParallelSparseMatrixProduct.h @@ -38,7 +38,7 @@ class ParallelSparseMatrixProduct void computeProductFromIntersection() override { - assert(this->m_intersectionAB.intersection.size() == this->m_productResult.nonZeros()); + assert(static_cast(this->m_intersectionAB.intersection.size()) == this->m_productResult.nonZeros()); assert(taskScheduler); auto* lhs_ptr = this->m_lhs->valuePtr(); From 95f769ca8a9c94ff9a194bc470410417631a971a Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Wed, 15 Apr 2026 08:27:42 +0900 Subject: [PATCH 2/7] remove warning about copying diff vec (using copy ctor from a different typed mat) --- Sofa/framework/Type/src/sofa/type/Mat.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sofa/framework/Type/src/sofa/type/Mat.h b/Sofa/framework/Type/src/sofa/type/Mat.h index 00a78497693..2f223c92034 100644 --- a/Sofa/framework/Type/src/sofa/type/Mat.h +++ b/Sofa/framework/Type/src/sofa/type/Mat.h @@ -167,7 +167,9 @@ class Mat template constexpr Mat(const Mat& m) noexcept { - std::copy(m.begin(), m.begin()+L, this->begin()); + for( Size i=0; i(m(i,j)); } /// Constructor from another matrix with different size (with null default entries and ignoring outside entries) From 831f9798f1dad2afc0b9120524cb7d71e61e2b18 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Wed, 15 Apr 2026 11:18:29 +0900 Subject: [PATCH 3/7] fix implicit conversions --- .../core/objectmodel/BaseObjectDescription.cpp | 2 +- .../sofa/core/topology/TopologySubsetData.inl | 8 ++++---- .../src/sofa/defaulttype/TypeInfoRegistry.cpp | 2 +- .../Helper/src/sofa/helper/AdvancedTimer.cpp | 2 +- .../src/sofa/helper/MarchingCubeUtility.cpp | 16 ++++++++-------- .../Helper/src/sofa/helper/TriangleOctree.cpp | 2 +- Sofa/framework/Helper/src/sofa/helper/Utils.cpp | 2 +- .../Helper/src/sofa/helper/io/MeshGmsh.cpp | 2 +- .../src/sofa/helper/system/PipeProcess.cpp | 2 +- .../src/sofa/linearalgebra/BlockDiagonalMatrix.h | 4 ++-- .../CompressedRowSparseMatrixConstraint.h | 2 +- .../Core/src/sofa/simulation/Colors.cpp | 2 +- .../MechanicalAddMBKdxVisitor.cpp | 2 +- .../MechanicalComputeDfVisitor.cpp | 2 +- Sofa/framework/Type/src/sofa/type/DualQuat.inl | 2 +- Sofa/framework/Type/src/sofa/type/Vec.h | 2 +- 16 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseObjectDescription.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseObjectDescription.cpp index 17d93b42274..97bbbea54e5 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseObjectDescription.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseObjectDescription.cpp @@ -141,7 +141,7 @@ int BaseObjectDescription::getAttributeAsInt(const std::string& attr, const int const char* attrstr=it->second.c_str(); char* end=nullptr; - const int retval = strtol(attrstr, &end, 10); + const int retval = static_cast(strtol(attrstr, &end, 10)); /// It is important to check that the attribute was totally parsed to report /// message to users because a silent error is the worse thing that can happen in UX. diff --git a/Sofa/framework/Core/src/sofa/core/topology/TopologySubsetData.inl b/Sofa/framework/Core/src/sofa/core/topology/TopologySubsetData.inl index a650d02dca5..9b99c23aebd 100644 --- a/Sofa/framework/Core/src/sofa/core/topology/TopologySubsetData.inl +++ b/Sofa/framework/Core/src/sofa/core/topology/TopologySubsetData.inl @@ -117,8 +117,8 @@ void TopologySubsetData ::add(sofa::Size nbElements, helper::WriteOnlyAccessor > data = this; // first resize the subsetData. value will be applied in the loop using callbacks - const Size size = data.size(); - data.resize(size + nbElements); + const Size size = static_cast(data.size()); + data.resize(size + static_cast(nbElements)); if (this->p_onCreationCallback) @@ -129,7 +129,7 @@ void TopologySubsetData ::add(sofa::Size nbElements, value_type& t = data[id]; // update map if needed - addPostProcess(LastDataId + i + 1); + addPostProcess(LastDataId + static_cast(i) + 1); this->p_onCreationCallback(id, t, elems[i], (ancestors.empty() || coefs.empty()) ? s_empty_ancestors : ancestors[i], @@ -154,7 +154,7 @@ void TopologySubsetData ::add(const sofa::type::vector { SOFA_UNUSED(ancestorElems); - const sofa::Size nbElements = index.size(); + const sofa::Size nbElements = static_cast(index.size()); this->add(nbElements, elems, ancestors, coefs); } diff --git a/Sofa/framework/DefaultType/src/sofa/defaulttype/TypeInfoRegistry.cpp b/Sofa/framework/DefaultType/src/sofa/defaulttype/TypeInfoRegistry.cpp index 0c47017cd26..3b9e92b6d04 100644 --- a/Sofa/framework/DefaultType/src/sofa/defaulttype/TypeInfoRegistry.cpp +++ b/Sofa/framework/DefaultType/src/sofa/defaulttype/TypeInfoRegistry.cpp @@ -90,7 +90,7 @@ int TypeInfoRegistry::AllocateNewTypeId(const std::type_info& nfo) const std::string name = sofa::helper::NameDecoder::decodeTypeName(nfo); const std::string typeName = sofa::helper::NameDecoder::decodeTypeName(nfo); typeinfos.push_back(new NameOnlyTypeInfo(name, typeName)); - return typeinfos.size()-1; + return static_cast(typeinfos.size()-1); } diff --git a/Sofa/framework/Helper/src/sofa/helper/AdvancedTimer.cpp b/Sofa/framework/Helper/src/sofa/helper/AdvancedTimer.cpp index 3bf86905226..81241ffa319 100644 --- a/Sofa/framework/Helper/src/sofa/helper/AdvancedTimer.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/AdvancedTimer.cpp @@ -1087,7 +1087,7 @@ std::string getTime(ctime_t t, int niter=1) double strToDouble(std::string const &stringToConvert, std::size_t const precision) { std::stringstream convertingStream; - convertingStream << std::setprecision(precision) << std::fixed << stringToConvert << std::endl; + convertingStream << std::setprecision(static_cast(precision)) << std::fixed << stringToConvert << std::endl; double answer; convertingStream >> answer; diff --git a/Sofa/framework/Helper/src/sofa/helper/MarchingCubeUtility.cpp b/Sofa/framework/Helper/src/sofa/helper/MarchingCubeUtility.cpp index 389a167f356..e207979b9af 100644 --- a/Sofa/framework/Helper/src/sofa/helper/MarchingCubeUtility.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/MarchingCubeUtility.cpp @@ -852,14 +852,14 @@ namespace sofa::helper void MarchingCubeUtility::updateTriangleInRegularGridVector ( type::vector< type::vector >& triangleIndexInRegularGrid, const type::Vec3i& coord, const GridCell& cell, unsigned int nbTriangles ) const { vector voxels; - if ( cell.val[0] ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+0 ) *m_dataResolution[0] + ( coord[2]+0 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube - if ( cell.val[1] ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+0 ) *m_dataResolution[0] + ( coord[2]+0 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube - if ( cell.val[3] ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+1 ) *m_dataResolution[0] + ( coord[2]+0 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube - if ( cell.val[2] ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+1 ) *m_dataResolution[0] + ( coord[2]+0 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube - if ( cell.val[4] ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+0 ) *m_dataResolution[0] + ( coord[2]+1 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube - if ( cell.val[5] ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+0 ) *m_dataResolution[0] + ( coord[2]+1 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube - if ( cell.val[7] ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+1 ) *m_dataResolution[0] + ( coord[2]+1 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube - if ( cell.val[6] ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+1 ) *m_dataResolution[0] + ( coord[2]+1 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[0] != 0 ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+0 ) *m_dataResolution[0] + ( coord[2]+0 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[1] != 0 ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+0 ) *m_dataResolution[0] + ( coord[2]+0 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[3] != 0 ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+1 ) *m_dataResolution[0] + ( coord[2]+0 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[2] != 0 ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+1 ) *m_dataResolution[0] + ( coord[2]+0 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[4] != 0 ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+0 ) *m_dataResolution[0] + ( coord[2]+1 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[5] != 0 ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+0 ) *m_dataResolution[0] + ( coord[2]+1 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[7] != 0 ) voxels.push_back ( ( coord[0]+0 ) + ( coord[1]+1 ) *m_dataResolution[0] + ( coord[2]+1 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube + if ( cell.val[6] != 0 ) voxels.push_back ( ( coord[0]+1 ) + ( coord[1]+1 ) *m_dataResolution[0] + ( coord[2]+1 ) *m_dataResolution[0]*m_dataResolution[1] ); //les voxels occupes ds ce cube for ( size_t i = 0; i < nbTriangles; i++ ) { diff --git a/Sofa/framework/Helper/src/sofa/helper/TriangleOctree.cpp b/Sofa/framework/Helper/src/sofa/helper/TriangleOctree.cpp index b97a13c15c3..f709ef99c61 100644 --- a/Sofa/framework/Helper/src/sofa/helper/TriangleOctree.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/TriangleOctree.cpp @@ -840,7 +840,7 @@ void TriangleOctreeRoot::buildOctree() // for each triangle add it to the octree for (size_t i = 0; i < octreeTriangles->size(); i++) { - fillOctree (i); + fillOctree (static_cast(i)); } } diff --git a/Sofa/framework/Helper/src/sofa/helper/Utils.cpp b/Sofa/framework/Helper/src/sofa/helper/Utils.cpp index 80087c8bac0..74a0f265443 100644 --- a/Sofa/framework/Helper/src/sofa/helper/Utils.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/Utils.cpp @@ -109,7 +109,7 @@ static std::string computeExecutablePath() #elif defined(__APPLE__) std::vector buffer(PATH_MAX); std::vector real_path(PATH_MAX); - uint32_t size = buffer.size(); + uint32_t size = static_cast(buffer.size()); if (_NSGetExecutablePath(&buffer[0], &size) != 0) { msg_error("Utils::computeExecutablePath()") << "_NSGetExecutablePath() failed"; } diff --git a/Sofa/framework/Helper/src/sofa/helper/io/MeshGmsh.cpp b/Sofa/framework/Helper/src/sofa/helper/io/MeshGmsh.cpp index 9e14bcad143..97e3069bdb8 100644 --- a/Sofa/framework/Helper/src/sofa/helper/io/MeshGmsh.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/io/MeshGmsh.cpp @@ -63,7 +63,7 @@ void MeshGmsh::init (std::string filename) std::getline(file, version); // Getting the version line (e.g. 4.1 0 8) try { - gmshFormat = std::stoul(version.substr( 0, version.find(" ")) ); // Retrieving the mesh format, keeping only the integer part + gmshFormat = static_cast(std::stoul(version.substr( 0, version.find(" ")) )); // Retrieving the mesh format, keeping only the integer part } catch (const std::exception&) { diff --git a/Sofa/framework/Helper/src/sofa/helper/system/PipeProcess.cpp b/Sofa/framework/Helper/src/sofa/helper/system/PipeProcess.cpp index aecfe2cfaff..5ecfe606de6 100644 --- a/Sofa/framework/Helper/src/sofa/helper/system/PipeProcess.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/system/PipeProcess.cpp @@ -306,7 +306,7 @@ bool PipeProcess::executeProcess(const std::string &command, const std::vector< { int n = BUFSIZE-nfill[i]; if (n> STEPSIZE) n = STEPSIZE; - n = ::read(fds[i][0], buf[i]+nfill[i], n); + n = static_cast(::read(fds[i][0], buf[i]+nfill[i], n)); if (n == 0) { diff --git a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/BlockDiagonalMatrix.h b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/BlockDiagonalMatrix.h index beb752b4e2a..4dab9d3369e 100644 --- a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/BlockDiagonalMatrix.h +++ b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/BlockDiagonalMatrix.h @@ -78,12 +78,12 @@ class BlockDiagonalMatrix : public linearalgebra::BaseMatrix Index rowBSize(void) const { - return data.size(); + return static_cast(data.size()); } Index colBSize(void) const { - return data.size(); + return static_cast(data.size()); } const Block& bloc(Index i) const diff --git a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraint.h b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraint.h index 51f583d017f..2e8ae05181a 100644 --- a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraint.h +++ b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixConstraint.h @@ -549,7 +549,7 @@ class CompressedRowSparseMatrixConstraint : public sofa::linearalgebra::Compress RowConstIterator readLine(Index lIndex) const { if constexpr (Policy::AutoCompress) const_cast(this)->compress(); /// \warning this violates the const-ness of the method ! - Index rowId = (this->nBlockRow == 0) ? 0 : lIndex * this->rowIndex.size() / this->nBlockRow; + Index rowId = (this->nBlockRow == 0) ? 0 : static_cast(lIndex * this->rowIndex.size() / this->nBlockRow); if (this->sortedFind(this->rowIndex, lIndex, rowId)) { return RowConstIterator(this, rowId); diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/Colors.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/Colors.cpp index bee044d6959..79013fe09d5 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/Colors.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/Colors.cpp @@ -104,7 +104,7 @@ const char* getColor(const sofa::Index id) sofa::Index registerColor(const std::string& hexColor) { DEFAULTCOLORS.emplace_back(hexColor); - return DEFAULTCOLORS.size()-1; + return static_cast(DEFAULTCOLORS.size()-1); } sofa::Index registerColor(const std::string& className, const std::string& hexColor) diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalAddMBKdxVisitor.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalAddMBKdxVisitor.cpp index ccf2a80e4d3..364d63e3b75 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalAddMBKdxVisitor.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalAddMBKdxVisitor.cpp @@ -49,7 +49,7 @@ void MechanicalAddMBKdxVisitor::bwdMechanicalMapping(simulation::Node* /*node*/, if (accumulate) { map->applyJT(mparams, res, res); - if( mparams->kFactor() ) map->applyDJT(mparams, res, res); + if( mparams->kFactor() != 0 ) map->applyDJT(mparams, res, res); } } diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalComputeDfVisitor.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalComputeDfVisitor.cpp index 7182b2a1237..2cb0b164ea5 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalComputeDfVisitor.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalComputeDfVisitor.cpp @@ -49,7 +49,7 @@ void MechanicalComputeDfVisitor::bwdMechanicalMapping(simulation::Node* /*node*/ if (accumulate) { map->applyJT(mparams, res, res); // apply material stiffness: variation of force below the mapping - if( mparams->kFactor() ) map->applyDJT(mparams, res, res); // apply geometric stiffness: variation due to a change of mapping, with a constant force below the mapping + if(mparams->kFactor() != 0) map->applyDJT(mparams, res, res); // apply geometric stiffness: variation due to a change of mapping, with a constant force below the mapping } } diff --git a/Sofa/framework/Type/src/sofa/type/DualQuat.inl b/Sofa/framework/Type/src/sofa/type/DualQuat.inl index 9e81b3c6dd0..72d283d1d16 100644 --- a/Sofa/framework/Type/src/sofa/type/DualQuat.inl +++ b/Sofa/framework/Type/src/sofa/type/DualQuat.inl @@ -170,7 +170,7 @@ void DualQuatCoord3::normalize_getdJ( type::Mat<4,4,real>& dJ0, type::Mat real q0dqe = (real) ( qn.orientation[0]*dq.dual[0] + qn.orientation[1]*dq.dual[1] + qn.orientation[2]*dq.dual[2] + qn.orientation[3]*dq.dual[3]); - if(dq.orientation[0] || dq.orientation[1] || dq.orientation[2] || dq.orientation[3]) + if(dq.orientation[0] != 0 || dq.orientation[1] != 0 || dq.orientation[2] != 0 || dq.orientation[3] != 0) { real q0dq0 = (real) ( qn.orientation[0]*dq.orientation[0] + qn.orientation[1]*dq.orientation[1] + qn.orientation[2]*dq.orientation[2] + qn.orientation[3]*dq.orientation[3]); real qedq0 = (real) ( qn.dual[0]*dq.orientation[0] + qn.dual[1]*dq.orientation[1] + qn.dual[2]*dq.orientation[2] + qn.dual[3]*dq.orientation[3]); diff --git a/Sofa/framework/Type/src/sofa/type/Vec.h b/Sofa/framework/Type/src/sofa/type/Vec.h index 315c9d0ed90..c63bb2483b4 100644 --- a/Sofa/framework/Type/src/sofa/type/Vec.h +++ b/Sofa/framework/Type/src/sofa/type/Vec.h @@ -517,7 +517,7 @@ class Vec { ValueType n=0; for( Size i=0; ielems[i] ) n+=1; + if( this->elems[i] != static_cast(0) ) n+=1; return n; } else // generic implementation From 7e08783d5791e7666da184596dfb9d98c29a29ce Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Wed, 15 Apr 2026 15:55:29 +0900 Subject: [PATCH 4/7] fix C4458 C4456 C4244 C4267 C4245 C4701 C4515 warnings --- .../Core/src/sofa/core/CollisionElement.h | 2 +- .../Core/src/sofa/core/ComponentLibrary.cpp | 2 +- .../Core/src/sofa/core/DataTracker.cpp | 4 +- Sofa/framework/Core/src/sofa/core/Mapping.cpp | 1 - Sofa/framework/Core/src/sofa/core/Mapping.inl | 52 +++++++++---------- .../Core/src/sofa/core/ObjectFactory.cpp | 6 +-- .../Core/src/sofa/core/SofaLibrary.cpp | 6 +-- .../behavior/DefaultMultiMatrixAccessor.cpp | 2 +- .../src/sofa/core/collision/Intersection.cpp | 18 +++---- .../Core/src/sofa/core/loader/VoxelLoader.cpp | 1 - .../sofa/core/objectmodel/BaseComponent.cpp | 4 +- .../src/sofa/core/objectmodel/BaseLink.cpp | 4 +- .../defaulttype/typeinfo/NameOnlyTypeInfo.h | 6 +-- .../sofa/defaulttype/typeinfo/NoTypeInfo.h | 6 +-- .../typeinfo/models/FixedArrayTypeInfo.h | 2 +- .../Helper/src/sofa/helper/AdvancedTimer.cpp | 2 +- .../Helper/src/sofa/helper/LCPcalc.cpp | 16 +++--- .../Helper/src/sofa/helper/TriangleOctree.cpp | 2 +- .../Helper/src/sofa/helper/io/ImageDDS.cpp | 10 ++-- .../src/sofa/helper/system/DynamicLibrary.cpp | 10 ++-- .../src/sofa/helper/system/SetDirectory.cpp | 8 ++- .../CompressedRowSparseMatrixGeneric.h | 2 +- .../src/sofa/simulation/RequiredPlugin.cpp | 14 ++--- .../src/sofa/simulation/VectorOperations.cpp | 6 +-- 24 files changed, 98 insertions(+), 88 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/CollisionElement.h b/Sofa/framework/Core/src/sofa/core/CollisionElement.h index 70134527f89..d384bc0e50a 100644 --- a/Sofa/framework/Core/src/sofa/core/CollisionElement.h +++ b/Sofa/framework/Core/src/sofa/core/CollisionElement.h @@ -59,7 +59,7 @@ class BaseCollisionElementIterator /// Constructor. /// This constructor should be used in case a vector of indices is used. BaseCollisionElementIterator(VIterator vit, VIterator vitend) - : index(-1), it(vit), itend(vitend) + : index(static_cast(-1)), it(vit), itend(vitend) { if (it != itend) index = *it; } diff --git a/Sofa/framework/Core/src/sofa/core/ComponentLibrary.cpp b/Sofa/framework/Core/src/sofa/core/ComponentLibrary.cpp index 0be471c02b2..491e001d3c9 100644 --- a/Sofa/framework/Core/src/sofa/core/ComponentLibrary.cpp +++ b/Sofa/framework/Core/src/sofa/core/ComponentLibrary.cpp @@ -29,7 +29,7 @@ namespace sofa::core std::string caseInsensitive(const std::string &text) { std::string result; result.resize(text.size()); - for (unsigned int i=0; i(toupper(text[i])); return result; } diff --git a/Sofa/framework/Core/src/sofa/core/DataTracker.cpp b/Sofa/framework/Core/src/sofa/core/DataTracker.cpp index 8feea63fe7f..0354bce2f04 100644 --- a/Sofa/framework/Core/src/sofa/core/DataTracker.cpp +++ b/Sofa/framework/Core/src/sofa/core/DataTracker.cpp @@ -87,8 +87,8 @@ void DataTrackerDDGNode::cleanDirty(const core::ExecParams*) void DataTrackerDDGNode::updateAllInputsIfDirty() { - const DDGLinkContainer& inputs = DDGNode::getInputs(); - for(const auto input : inputs) + const DDGLinkContainer& ddgInputs = DDGNode::getInputs(); + for(const auto input : ddgInputs) { static_cast(input)->updateIfDirty(); } diff --git a/Sofa/framework/Core/src/sofa/core/Mapping.cpp b/Sofa/framework/Core/src/sofa/core/Mapping.cpp index 7d0dca17b0a..360be869490 100644 --- a/Sofa/framework/Core/src/sofa/core/Mapping.cpp +++ b/Sofa/framework/Core/src/sofa/core/Mapping.cpp @@ -28,7 +28,6 @@ namespace sofa::core { using namespace sofa::defaulttype; -using namespace core; template class SOFA_CORE_API Mapping< sofa::defaulttype::Vec1Types, sofa::defaulttype::Vec1Types >; template class SOFA_CORE_API Mapping< sofa::defaulttype::Vec1Types, sofa::defaulttype::Vec2Types >; diff --git a/Sofa/framework/Core/src/sofa/core/Mapping.inl b/Sofa/framework/Core/src/sofa/core/Mapping.inl index 48624dc065b..5639eda600f 100644 --- a/Sofa/framework/Core/src/sofa/core/Mapping.inl +++ b/Sofa/framework/Core/src/sofa/core/Mapping.inl @@ -135,12 +135,12 @@ sofa::linearalgebra::BaseMatrix* Mapping::createMappedMatrix(const behav template void Mapping::apply(const MechanicalParams* mparams, MultiVecCoordId outPos, ConstMultiVecCoordId inPos) { - State* fromModel = this->fromModel.get(); - State* toModel = this->toModel.get(); - if(fromModel && toModel) + State* from = this->fromModel.get(); + State* to = this->toModel.get(); + if(from && to) { - OutDataVecCoord* out = outPos[toModel].write(); - const InDataVecCoord* in = inPos[fromModel].read(); + OutDataVecCoord* out = outPos[to].write(); + const InDataVecCoord* in = inPos[from].read(); if(out && in) { this->apply(mparams, *out, *in); @@ -151,12 +151,12 @@ void Mapping::apply(const MechanicalParams* mparams, MultiVecCoordId out template void Mapping::applyJ(const MechanicalParams* mparams, MultiVecDerivId outVel, ConstMultiVecDerivId inVel) { - State* fromModel = this->fromModel.get(); - State* toModel = this->toModel.get(); - if(fromModel && toModel) + State* from = this->fromModel.get(); + State* to = this->toModel.get(); + if(from && to) { - OutDataVecDeriv* out = outVel[toModel].write(); - const InDataVecDeriv* in = inVel[fromModel].read(); + OutDataVecDeriv* out = outVel[to].write(); + const InDataVecDeriv* in = inVel[from].read(); if(out && in) { this->applyJ(mparams, *out, *in); @@ -167,12 +167,12 @@ void Mapping::applyJ(const MechanicalParams* mparams, MultiVecDerivId ou template void Mapping::applyJT(const MechanicalParams *mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce) { - State* fromModel = this->fromModel.get(); - State* toModel = this->toModel.get(); - if(fromModel && toModel) + State* from = this->fromModel.get(); + State* to = this->toModel.get(); + if(from && to) { - InDataVecDeriv* out = inForce[fromModel].write(); - const OutDataVecDeriv* in = outForce[toModel].read(); + InDataVecDeriv* out = inForce[from].write(); + const OutDataVecDeriv* in = outForce[to].read(); if(out && in) { this->applyJT(mparams, *out, *in); @@ -184,12 +184,12 @@ void Mapping::applyJT(const MechanicalParams *mparams, MultiVecDerivId i template void Mapping::applyJT(const ConstraintParams* cparams, MultiMatrixDerivId inConst, ConstMultiMatrixDerivId outConst ) { - State* fromModel = this->fromModel.get(); - State* toModel = this->toModel.get(); - if(fromModel && toModel) + State* from = this->fromModel.get(); + State* to = this->toModel.get(); + if(from && to) { - InDataMatrixDeriv* out = inConst[fromModel].write(); - const OutDataMatrixDeriv* in = outConst[toModel].read(); + InDataMatrixDeriv* out = inConst[from].write(); + const OutDataMatrixDeriv* in = outConst[to].read(); if(out && in) { this->applyJT(cparams, *out, *in); @@ -208,13 +208,13 @@ void Mapping::applyDJT(const MechanicalParams* /*mparams */ , MultiVecDe template void Mapping::computeAccFromMapping(const MechanicalParams* mparams, MultiVecDerivId outAcc, ConstMultiVecDerivId inVel, ConstMultiVecDerivId inAcc ) { - State* fromModel = this->fromModel.get(); - State* toModel = this->toModel.get(); - if(fromModel && toModel) + State* from = this->fromModel.get(); + State* to = this->toModel.get(); + if(from && to) { - OutDataVecDeriv* out = outAcc[toModel].write(); - const InDataVecDeriv* inV = inVel[fromModel].read(); - const InDataVecDeriv* inA = inAcc[fromModel].read(); + OutDataVecDeriv* out = outAcc[to].write(); + const InDataVecDeriv* inV = inVel[from].read(); + const InDataVecDeriv* inA = inAcc[from].read(); if(out && inV && inA) this->computeAccFromMapping(mparams, *out, *inV, *inA); } diff --git a/Sofa/framework/Core/src/sofa/core/ObjectFactory.cpp b/Sofa/framework/Core/src/sofa/core/ObjectFactory.cpp index 69d8f071a95..24947674ec5 100644 --- a/Sofa/framework/Core/src/sofa/core/ObjectFactory.cpp +++ b/Sofa/framework/Core/src/sofa/core/ObjectFactory.cpp @@ -529,7 +529,7 @@ void ObjectFactory::dump(std::ostream& out) if (!entry->aliases.empty()) { out << " aliases :"; - for (std::set::iterator myit = entry->aliases.begin(), itend = entry->aliases.end(); myit != itend; ++myit) + for (std::set::iterator myit = entry->aliases.begin(), aliasesEnd = entry->aliases.end(); myit != aliasesEnd; ++myit) out << " " << *myit; out << "\n"; } @@ -573,7 +573,7 @@ void ObjectFactory::dumpXML(std::ostream& out) const ClassEntry::SPtr entry = it->second; if (entry->className != it->first) continue; out << "className) <<"\">\n"; - for (std::set::iterator myit = entry->aliases.begin(), itend = entry->aliases.end(); myit != itend; ++myit) + for (std::set::iterator myit = entry->aliases.begin(), aliasesEnd = entry->aliases.end(); myit != aliasesEnd; ++myit) out << "" << xmlencode(*myit) << "\n"; if (!entry->description.empty()) out << ""<description<<"\n"; @@ -607,7 +607,7 @@ void ObjectFactory::dumpHTML(std::ostream& out) if (!entry->aliases.empty()) { out << "
  • Aliases:"; - for (std::set::iterator myit = entry->aliases.begin(), itend = entry->aliases.end(); myit != itend; ++myit) + for (std::set::iterator myit = entry->aliases.begin(), aliasesEnd = entry->aliases.end(); myit != aliasesEnd; ++myit) out << " " << xmlencode(*myit); out << "
  • \n"; } diff --git a/Sofa/framework/Core/src/sofa/core/SofaLibrary.cpp b/Sofa/framework/Core/src/sofa/core/SofaLibrary.cpp index 65e47de3f5b..0b29730050e 100644 --- a/Sofa/framework/Core/src/sofa/core/SofaLibrary.cpp +++ b/Sofa/framework/Core/src/sofa/core/SofaLibrary.cpp @@ -48,9 +48,9 @@ void SofaLibrary::build( const std::vector< std::string >& examples) if (creatorEntry != entries[i]->creatorMap.end()) { const objectmodel::BaseClass* baseClass = creatorEntry->second->getClass(); - std::vector categories; - CategoryLibrary::getCategories(baseClass, categories); - for (std::vector::iterator it = categories.begin(); it != categories.end(); ++it) + std::vector categoriesVec; + CategoryLibrary::getCategories(baseClass, categoriesVec); + for (std::vector::iterator it = categoriesVec.begin(); it != categoriesVec.end(); ++it) { mainCategories.insert((*it)); inventory.insert(std::make_pair((*it), entries[i])); diff --git a/Sofa/framework/Core/src/sofa/core/behavior/DefaultMultiMatrixAccessor.cpp b/Sofa/framework/Core/src/sofa/core/behavior/DefaultMultiMatrixAccessor.cpp index a49c379b1ab..074aa956264 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/DefaultMultiMatrixAccessor.cpp +++ b/Sofa/framework/Core/src/sofa/core/behavior/DefaultMultiMatrixAccessor.cpp @@ -52,7 +52,7 @@ void DefaultMultiMatrixAccessor::clear() { globalDim = 0; for (auto it = realStateOffsets.begin(), itend = realStateOffsets.end(); it != itend; ++it) - it->second = -1; + it->second = static_castsecond)>(-1); for (std::map< const sofa::core::behavior::BaseMechanicalState*, linearalgebra::BaseMatrix* >::iterator it = mappedMatrices.begin(), itend = mappedMatrices.end(); it != itend; ++it) if (it->second != nullptr) delete it->second; diff --git a/Sofa/framework/Core/src/sofa/core/collision/Intersection.cpp b/Sofa/framework/Core/src/sofa/core/collision/Intersection.cpp index e5bdada8a24..425148701d8 100644 --- a/Sofa/framework/Core/src/sofa/core/collision/Intersection.cpp +++ b/Sofa/framework/Core/src/sofa/core/collision/Intersection.cpp @@ -42,11 +42,11 @@ helper::TypeInfo IntersectorMap::getType(core::CollisionModel* model) if (it == castMap.end()) { helper::TypeInfo t2 = t; - for (std::set::iterator it = classes.begin(); it != classes.end(); ++it) + for (std::set::iterator ci = classes.begin(); ci != classes.end(); ++ci) { - if ((*it)->isInstance(model)) + if ((*ci)->isInstance(model)) { - t2 = (*it)->type(); + t2 = (*ci)->type(); break; } } @@ -76,14 +76,14 @@ ElementIntersector* IntersectorMap::get(core::CollisionModel* model1, core::Coll std::stringstream tmp; - for(InternalMap::const_iterator it = intersectorsMap.begin(), itEnd = intersectorsMap.end(); it != itEnd; ++it) + for(InternalMap::const_iterator it2 = intersectorsMap.begin(), itEnd = intersectorsMap.end(); it2 != itEnd; ++it2) { - helper::TypeInfo t1 = it->first.first; - helper::TypeInfo t2 = it->first.second; + helper::TypeInfo t1_tmp = it2->first.first; + helper::TypeInfo t2_tmp = it2->first.second; tmp << " " - << gettypename(t1) << "-" - << gettypename(t2); - const ElementIntersector* i = it->second; + << gettypename(t1_tmp) << "-" + << gettypename(t2_tmp); + const ElementIntersector* i = it2->second; if (!i) tmp << " nullptr"; else diff --git a/Sofa/framework/Core/src/sofa/core/loader/VoxelLoader.cpp b/Sofa/framework/Core/src/sofa/core/loader/VoxelLoader.cpp index f56f4c49984..edce2a8a7bb 100644 --- a/Sofa/framework/Core/src/sofa/core/loader/VoxelLoader.cpp +++ b/Sofa/framework/Core/src/sofa/core/loader/VoxelLoader.cpp @@ -35,7 +35,6 @@ namespace sofa::core::loader { using namespace sofa::defaulttype; -using namespace sofa::core::loader; VoxelLoader::VoxelLoader() :BaseLoader() diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp index 827aa9659bb..656955cdd71 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseComponent.cpp @@ -209,11 +209,11 @@ const BaseComponent::VecSlaves& BaseComponent::getSlaves() const return l_slaves.getValue(); } -BaseComponent* BaseComponent::getSlave(const std::string& name) const +BaseComponent* BaseComponent::getSlave(const std::string& slaveName) const { for (auto slave : l_slaves) { - if (slave.get() && slave->getName() == name) + if (slave.get() && slave->getName() == slaveName) return slave.get(); } return nullptr; diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseLink.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseLink.cpp index 0e9287cd8c5..c056c2ef233 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/BaseLink.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/BaseLink.cpp @@ -316,9 +316,9 @@ bool BaseLink::read( const std::string& str ) /// Add the detected objects that are not already present to the container of this Link clear(); - for (const auto& [base, path] : entries) + for (const auto& [base, linkPath] : entries) { - ok = add(base, path) && ok; + ok = add(base, linkPath) && ok; } return ok; } diff --git a/Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/NameOnlyTypeInfo.h b/Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/NameOnlyTypeInfo.h index 536139cb058..d527da93bf8 100644 --- a/Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/NameOnlyTypeInfo.h +++ b/Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/NameOnlyTypeInfo.h @@ -78,16 +78,16 @@ class SOFA_DEFAULTTYPE_API NameOnlyTypeInfo : public AbstractTypeInfo /// and those six elements are conceptually numbered from 0 to 5. This is /// relevant only if FixedSize() is true. I FixedSize() is false, /// the return value will be equivalent to the one of byteSize() - sofa::Size size() const override {return -1;} + sofa::Size size() const override {return static_cast(-1);} /// The size in bytes of the ValueType /// For example, the size of a fixed_array, 3>` is 4 on most systems, /// as it is the byte size of the smallest dimension in the array (int -> 32bit) - sofa::Size byteSize() const override {return -1;} + sofa::Size byteSize() const override {return static_cast(-1);} /// The size of \a data, in number of iterable elements /// (For containers, that'll be the number of elements in the 1st dimension). /// For example, with type == ` - sofa::Size size(const void* /*data*/) const override {return -1;} + sofa::Size size(const void* /*data*/) const override {return static_cast(-1);} /// Resize \a data to \a size elements, if relevant. /// But resizing is not always relevant, for example: diff --git a/Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/NoTypeInfo.h b/Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/NoTypeInfo.h index c5504fcef93..e6fea5d5d85 100644 --- a/Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/NoTypeInfo.h +++ b/Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/NoTypeInfo.h @@ -74,16 +74,16 @@ class SOFA_DEFAULTTYPE_API NoTypeInfo : public AbstractTypeInfo /// and those six elements are conceptually numbered from 0 to 5. This is /// relevant only if FixedSize() is true. I FixedSize() is false, /// the return value will be equivalent to the one of byteSize() - sofa::Size size() const override {return -1;} + sofa::Size size() const override {return static_cast(-1);} /// The size in bytes of the ValueType /// For example, the size of a fixed_array, 3>` is 4 on most systems, /// as it is the byte size of the smallest dimension in the array (int -> 32bit) - sofa::Size byteSize() const override {return -1;} + sofa::Size byteSize() const override {return static_cast(-1);} /// The size of \a data, in number of iterable elements /// (For containers, that'll be the number of elements in the 1st dimension). /// For example, with type == ` - sofa::Size size(const void* /*data*/) const override {return -1;} + sofa::Size size(const void* /*data*/) const override {return static_cast(-1);} /// Resize \a data to \a size elements, if relevant. /// But resizing is not always relevant, for example: diff --git a/Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/models/FixedArrayTypeInfo.h b/Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/models/FixedArrayTypeInfo.h index f8d3bb3eac7..e8240ccc5e8 100644 --- a/Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/models/FixedArrayTypeInfo.h +++ b/Sofa/framework/DefaultType/src/sofa/defaulttype/typeinfo/models/FixedArrayTypeInfo.h @@ -80,7 +80,7 @@ struct FixedArrayTypeInfo { if constexpr (!FixedSize) { - size /= data.size(); + size /= static_cast(data.size()); for (sofa::Size i = 0; i < data.size(); ++i) { if (!BaseTypeInfo::setSize(data[(sofa::Size)i], size)) diff --git a/Sofa/framework/Helper/src/sofa/helper/AdvancedTimer.cpp b/Sofa/framework/Helper/src/sofa/helper/AdvancedTimer.cpp index 81241ffa319..3dc21eade02 100644 --- a/Sofa/framework/Helper/src/sofa/helper/AdvancedTimer.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/AdvancedTimer.cpp @@ -934,7 +934,7 @@ void TimerData::print() AdvancedTimer::outputType AdvancedTimer::convertOutputType(std::string type) { std::for_each(type.begin(), type.end(), [](char& c) { - c = std::tolower(static_cast(c)); } ); + c = static_cast(std::tolower(static_cast(c))); } ); if(type.compare("json") == 0) return JSON; diff --git a/Sofa/framework/Helper/src/sofa/helper/LCPcalc.cpp b/Sofa/framework/Helper/src/sofa/helper/LCPcalc.cpp index 30fe39bffdb..18c54579ed7 100644 --- a/Sofa/framework/Helper/src/sofa/helper/LCPcalc.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/LCPcalc.cpp @@ -113,7 +113,7 @@ void LCP::setLCP(unsigned int input_dim, SReal *input_dfree, SReal **input_W, SR void LCP::solveNLCP(bool convergenceTest, std::vector* residuals, std::vector* violations) { //SReal error; - SReal f_1[3],dn, ds, dt; + SReal f_1_local[3],dn, ds, dt; const int numContacts = dim/3; const bool computeError = (convergenceTest || residuals); for (it=0; it* residuals, std::ve error = 0; for (int c=0; c* residuals, std::ve if (f[3*c]<0) { - if (f_1[0]>0 && computeError) // the point was in contact and is no more in contact.. + if (f_1_local[0]>0 && computeError) // the point was in contact and is no more in contact.. { for (int j=0; j<3; j++ ) { - Ddn -= W[3*c ][3*c+j]*f_1[j]; - Ddt -= W[3*c+1][3*c+j]*f_1[j]; - Dds -= W[3*c+2][3*c+j]*f_1[j]; + Ddn -= W[3*c ][3*c+j]*f_1_local[j]; + Ddt -= W[3*c+1][3*c+j]*f_1_local[j]; + Dds -= W[3*c+2][3*c+j]*f_1_local[j]; } error += sqrt(Ddn*Ddn + Ddt*Ddt + Dds*Dds); } @@ -161,8 +161,8 @@ void LCP::solveNLCP(bool convergenceTest, std::vector* residuals, std::ve ////// FRICTION // evaluation of the current tangent positions (motion du to force change along normal) - dt += W[3*c+1][3*c]*(f[3*c]-f_1[0]); - ds += W[3*c+2][3*c]*(f[3*c]-f_1[0]); + dt += W[3*c+1][3*c]*(f[3*c]-f_1_local[0]); + ds += W[3*c+2][3*c]*(f[3*c]-f_1_local[0]); // envaluation of the new fricton forces diff --git a/Sofa/framework/Helper/src/sofa/helper/TriangleOctree.cpp b/Sofa/framework/Helper/src/sofa/helper/TriangleOctree.cpp index f709ef99c61..be8da619c0a 100644 --- a/Sofa/framework/Helper/src/sofa/helper/TriangleOctree.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/TriangleOctree.cpp @@ -840,7 +840,7 @@ void TriangleOctreeRoot::buildOctree() // for each triangle add it to the octree for (size_t i = 0; i < octreeTriangles->size(); i++) { - fillOctree (static_cast(i)); + fillOctree(static_cast(i)); } } diff --git a/Sofa/framework/Helper/src/sofa/helper/io/ImageDDS.cpp b/Sofa/framework/Helper/src/sofa/helper/io/ImageDDS.cpp index 917475d4c8b..c60c0e19ed3 100644 --- a/Sofa/framework/Helper/src/sofa/helper/io/ImageDDS.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/io/ImageDDS.cpp @@ -204,11 +204,13 @@ bool ImageDDS::load(std::string filename) //case DDS_FORMAT_BGR32F: type = Image::FLOAT; channels = Image::BGR; break; //case DDS_FORMAT_BGRA32F: type = Image::FLOAT; channels = Image::BGRA; break; - default: - { - bool error = false; + default: + { + bool error = false; + type = Image::UNORM8; // Initialize with a default value + channels = Image::L; // Initialize with a default value - switch (header.ddpfPixelFormat.dwRGBBitCount) + switch (header.ddpfPixelFormat.dwRGBBitCount) { // 8bit formats (R8, L8) case 8: diff --git a/Sofa/framework/Helper/src/sofa/helper/system/DynamicLibrary.cpp b/Sofa/framework/Helper/src/sofa/helper/system/DynamicLibrary.cpp index fa90b3195f2..08eb4f4f15d 100644 --- a/Sofa/framework/Helper/src/sofa/helper/system/DynamicLibrary.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/system/DynamicLibrary.cpp @@ -177,9 +177,13 @@ void DynamicLibrary::fetchLastError() m_lastError = std::string(pMsgBuf); # else std::wstring s(pMsgBuf); - // This is terrible, it will truncate wchar_t to char_t, - // but it should work for characters 0 to 127. - m_lastError = std::string(s.begin(), s.end()); + // Convert wide string to narrow string properly + int size = WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, nullptr, 0, NULL, FALSE); + if (size > 0) + { + m_lastError.resize(size - 1); + WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, &m_lastError[0], size, NULL, FALSE); + } # endif LocalFree(pMsgBuf); #else diff --git a/Sofa/framework/Helper/src/sofa/helper/system/SetDirectory.cpp b/Sofa/framework/Helper/src/sofa/helper/system/SetDirectory.cpp index dd4eddbb9cb..21e5db02d92 100644 --- a/Sofa/framework/Helper/src/sofa/helper/system/SetDirectory.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/system/SetDirectory.cpp @@ -174,7 +174,13 @@ std::string SetDirectory::GetProcessFullPath(const char* filename) GetModuleFileName(nullptr,tpath,1024); std::wstring wprocessPath = tpath; std::string processPath; - processPath.assign(wprocessPath.begin(), wprocessPath.end() ); + // Convert wide string to narrow string properly + int size = WideCharToMultiByte(CP_UTF8, 0, wprocessPath.c_str(), -1, nullptr, 0, NULL, FALSE); + if (size > 0) + { + processPath.resize(size - 1); + WideCharToMultiByte(CP_UTF8, 0, wprocessPath.c_str(), -1, &processPath[0], size, NULL, FALSE); + } return processPath; } /// \TODO use GetCommandLineW and/or CommandLineToArgvW. This is however not strictly necessary, as argv[0] already contains the full path in most cases. diff --git a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixGeneric.h b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixGeneric.h index 119b451abb8..cc6434b66eb 100644 --- a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixGeneric.h +++ b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixGeneric.h @@ -452,7 +452,7 @@ public : for (std::size_t r = std::size_t(rowId); r < rowBegin.size()-1; ++r) { - rowBegin[r+1] -= nnzRow; + rowBegin[r+1] -= static_cast(nnzRow); } rowBegin.erase(rowBegin.begin()+rowId); rowIndex.erase(rowIndex.begin()+rowId); diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/RequiredPlugin.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/RequiredPlugin.cpp index 8a8e0c8185e..a804cd092a0 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/RequiredPlugin.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/RequiredPlugin.cpp @@ -128,27 +128,27 @@ bool RequiredPlugin::loadPlugin() std::ostringstream errmsg; for (const auto& pluginName : pluginsToLoad) { - const std::string name = FileSystem::cleanPath( pluginName ); // name is not necessarily a path + const std::string pluginFilePath = FileSystem::cleanPath( pluginName ); // pluginFilePath is not necessarily a path bool isNameLoaded = false; for (const auto& suffix : suffixVec) { - bool isPluginLoaded = pluginManager.pluginIsLoaded(name); + bool isPluginLoaded = pluginManager.pluginIsLoaded(pluginFilePath); if (!isPluginLoaded) { - const auto status = pluginManager.loadPlugin(name, suffix, true, true, &errmsg); + const auto status = pluginManager.loadPlugin(pluginFilePath, suffix, true, true, &errmsg); isPluginLoaded = (status == PluginManager::PluginLoadStatus::SUCCESS || status == PluginManager::PluginLoadStatus::ALREADY_LOADED); } if (isPluginLoaded) { - loadedPlugins.push_back(name); + loadedPlugins.push_back(pluginFilePath); isNameLoaded = true; // Register Objects explicitly - objectFactory->registerObjectsFromPlugin(name); + objectFactory->registerObjectsFromPlugin(pluginFilePath); // fail-safe to check if potential components have been registered (implicitly or explicitly) std::vector entries; - objectFactory->getEntriesFromTarget(entries, name); + objectFactory->getEntriesFromTarget(entries, pluginFilePath); if (entries.empty()) { @@ -164,7 +164,7 @@ bool RequiredPlugin::loadPlugin() } if (!isNameLoaded) { - failed.push_back(name); + failed.push_back(pluginFilePath); } else if (d_stopAfterFirstNameFound.getValue()) { diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/VectorOperations.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/VectorOperations.cpp index 9449aa4f2be..dc352463dfc 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/VectorOperations.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/VectorOperations.cpp @@ -186,9 +186,9 @@ void VectorOperations::print(sofa::core::ConstMultiVecId v, std::ostream &out, s size_t VectorOperations::v_size(core::MultiVecId v) { - size_t result = 0; - executeVisitor( MechanicalVSizeVisitor(params,&result,v) ); - return result; + size_t vecSize = 0; + executeVisitor( MechanicalVSizeVisitor(params,&vecSize,v) ); + return vecSize; } SReal VectorOperations::finish() From d8f357bfdef4fb26b00477fa1a7907af39e1e09c Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Thu, 16 Apr 2026 09:49:58 +0900 Subject: [PATCH 5/7] fix warning C4244 C4189 --- Sofa/framework/Helper/src/sofa/helper/DiffLib.cpp | 4 ++-- .../Simulation/Core/src/sofa/simulation/task/WorkerThread.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sofa/framework/Helper/src/sofa/helper/DiffLib.cpp b/Sofa/framework/Helper/src/sofa/helper/DiffLib.cpp index 5bc31dd54db..e4e1156368e 100644 --- a/Sofa/framework/Helper/src/sofa/helper/DiffLib.cpp +++ b/Sofa/framework/Helper/src/sofa/helper/DiffLib.cpp @@ -36,10 +36,10 @@ std::vector> SOFA_HELPER_API getClosestMatch(cons class Tuple { public: - Tuple(float ratio_, std::string value_) + Tuple(SReal ratio_, std::string value_) : ratio(ratio_), value(std::move(value_)) {} - float ratio; + SReal ratio; std::string value; }; auto cmp = [](const Tuple& left, Tuple& right) { return left.ratio < right.ratio; }; diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/task/WorkerThread.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/task/WorkerThread.cpp index f59b55ac123..9f5e1247761 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/task/WorkerThread.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/task/WorkerThread.cpp @@ -75,7 +75,7 @@ void WorkerThread::run(void) { #ifdef WIN32 const std::wstring widestr = std::wstring(m_name.begin(), m_name.end()); - HRESULT r = SetThreadDescription( + (void)SetThreadDescription( GetCurrentThread(), widestr.c_str() ); From 68f9430b7acad7846e37406a3124e389b6d0457a Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Thu, 16 Apr 2026 10:57:22 +0900 Subject: [PATCH 6/7] ignore warning 4589 --- Sofa/framework/Config/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sofa/framework/Config/CMakeLists.txt b/Sofa/framework/Config/CMakeLists.txt index e89cac3103a..d6ac0103998 100644 --- a/Sofa/framework/Config/CMakeLists.txt +++ b/Sofa/framework/Config/CMakeLists.txt @@ -181,6 +181,9 @@ endif() ## Windows-specific if(WIN32) list(APPEND SOFACONFIG_COMPILE_OPTIONS "/W4") + # MSVC warning suppressions + list(APPEND SOFACONFIG_COMPILE_OPTIONS "/wd4589") # Constructor of abstract class ignores initializer for virtual base class + list(APPEND SOFACONFIG_COMPILE_OPTIONS "-D_USE_MATH_DEFINES") list(APPEND SOFACONFIG_COMPILE_OPTIONS "-D_CRT_SECURE_NO_WARNINGS") list(APPEND SOFACONFIG_COMPILE_OPTIONS "-D_CRT_NONSTDC_NO_DEPRECATE") From 6241825570d6d48e6f0fa957f15e9461cf05cf06 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Mon, 11 May 2026 16:18:23 +0900 Subject: [PATCH 7/7] fix compilation error with clang --- .../src/sofa/linearalgebra/CompressedRowSparseMatrixGeneric.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixGeneric.h b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixGeneric.h index cc6434b66eb..066e72b8604 100644 --- a/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixGeneric.h +++ b/Sofa/framework/LinearAlgebra/src/sofa/linearalgebra/CompressedRowSparseMatrixGeneric.h @@ -452,7 +452,7 @@ public : for (std::size_t r = std::size_t(rowId); r < rowBegin.size()-1; ++r) { - rowBegin[r+1] -= static_cast(nnzRow); + rowBegin[r+1] -= static_cast(nnzRow); } rowBegin.erase(rowBegin.begin()+rowId); rowIndex.erase(rowIndex.begin()+rowId);