Skip to content

Commit

Permalink
Obj: Fix Sonarcube findings (assimp#5873)
Browse files Browse the repository at this point in the history
* Obj: Fix Sonarcube findings
  • Loading branch information
kimkulling authored Nov 11, 2024
1 parent f7bb1bc commit 9723b35
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions code/AssetLib/Obj/ObjFileImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static constexpr aiImporterDesc desc = {
"obj"
};

static const unsigned int ObjMinSize = 16;
static constexpr unsigned int ObjMinSize = 16u;

namespace Assimp {

Expand Down Expand Up @@ -163,7 +163,7 @@ void ObjFileImporter::InternReadFile(const std::string &file, aiScene *pScene, I
// ------------------------------------------------------------------------------------------------
// Create the data from parsed obj-file
void ObjFileImporter::CreateDataFromImport(const ObjFile::Model *pModel, aiScene *pScene) {
if (nullptr == pModel) {
if (pModel == nullptr) {
return;
}

Expand All @@ -178,7 +178,6 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model *pModel, aiScene
}

if (!pModel->mObjects.empty()) {

unsigned int meshCount = 0;
unsigned int childCount = 0;

Expand Down Expand Up @@ -258,8 +257,7 @@ void ObjFileImporter::CreateDataFromImport(const ObjFile::Model *pModel, aiScene
aiNode *ObjFileImporter::createNodes(const ObjFile::Model *pModel, const ObjFile::Object *pObject,
aiNode *pParent, aiScene *pScene,
std::vector<std::unique_ptr<aiMesh>> &MeshArray) {
ai_assert(nullptr != pModel);
if (nullptr == pObject) {
if (nullptr == pObject || pModel == nullptr) {
return nullptr;
}

Expand Down Expand Up @@ -311,16 +309,13 @@ aiNode *ObjFileImporter::createNodes(const ObjFile::Model *pModel, const ObjFile
// ------------------------------------------------------------------------------------------------
// Create topology data
std::unique_ptr<aiMesh> ObjFileImporter::createTopology(const ObjFile::Model *pModel, const ObjFile::Object *pData, unsigned int meshIndex) {
// Checking preconditions
ai_assert(nullptr != pModel);

if (nullptr == pData) {
if (nullptr == pData || pModel == nullptr) {
return nullptr;
}

// Create faces
ObjFile::Mesh *pObjMesh = pModel->mMeshes[meshIndex];
if (!pObjMesh) {
if (pObjMesh == nullptr) {
return nullptr;
}

Expand All @@ -335,7 +330,10 @@ std::unique_ptr<aiMesh> ObjFileImporter::createTopology(const ObjFile::Model *pM

for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++) {
const ObjFile::Face *inp = pObjMesh->m_Faces[index];

if (inp == nullptr) {
continue;
}

if (inp->mPrimitiveType == aiPrimitiveType_LINE) {
pMesh->mNumFaces += static_cast<unsigned int>(inp->m_vertices.size() - 1);
pMesh->mPrimitiveTypes |= aiPrimitiveType_LINE;
Expand All @@ -352,14 +350,14 @@ std::unique_ptr<aiMesh> ObjFileImporter::createTopology(const ObjFile::Model *pM
}
}

unsigned int uiIdxCount(0u);
unsigned int uiIdxCount = 0u;
if (pMesh->mNumFaces > 0) {
pMesh->mFaces = new aiFace[pMesh->mNumFaces];
if (pObjMesh->m_uiMaterialIndex != ObjFile::Mesh::NoMaterial) {
pMesh->mMaterialIndex = pObjMesh->m_uiMaterialIndex;
}

unsigned int outIndex(0);
unsigned int outIndex = 0u;

// Copy all data from all stored meshes
for (auto &face : pObjMesh->m_Faces) {
Expand Down Expand Up @@ -403,11 +401,14 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model *pModel,
aiMesh *pMesh,
unsigned int numIndices) {
// Checking preconditions
ai_assert(nullptr != pCurrentObject);
if (pCurrentObject == nullptr) {
return;
}

// Break, if no faces are stored in object
if (pCurrentObject->m_Meshes.empty())
if (pCurrentObject->m_Meshes.empty()) {
return;
}

// Get current mesh
ObjFile::Mesh *pObjMesh = pModel->mMeshes[uiMeshIndex];
Expand Down Expand Up @@ -586,11 +587,12 @@ void ObjFileImporter::createMaterials(const ObjFile::Model *pModel, aiScene *pSc
it = pModel->mMaterialMap.find(pModel->mMaterialLib[matIndex]);

// No material found, use the default material
if (pModel->mMaterialMap.end() == it)
if (pModel->mMaterialMap.end() == it) {
continue;
}

aiMaterial *mat = new aiMaterial;
ObjFile::Material *pCurrentMaterial = (*it).second;
ObjFile::Material *pCurrentMaterial = it->second;
mat->AddProperty(&pCurrentMaterial->MaterialName, AI_MATKEY_NAME);

// convert illumination model
Expand Down Expand Up @@ -777,8 +779,11 @@ void ObjFileImporter::createMaterials(const ObjFile::Model *pModel, aiScene *pSc
// Appends this node to the parent node
void ObjFileImporter::appendChildToParentNode(aiNode *pParent, aiNode *pChild) {
// Checking preconditions
ai_assert(nullptr != pParent);
ai_assert(nullptr != pChild);
if (pParent == nullptr || pChild == nullptr) {
ai_assert(nullptr != pParent);
ai_assert(nullptr != pChild);
return;
}

// Assign parent to child
pChild->mParent = pParent;
Expand Down

0 comments on commit 9723b35

Please sign in to comment.