Skip to content

Commit 3848272

Browse files
authored
[src] Fix SofaVisualMesh updateMesh method, bad init and forgot some delete (#32)
* Fix bad allocation in SofaVIsualMesh * backup some log * up log for debug
1 parent cc4e163 commit 3848272

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

Source/SofaUE5/Private/SofaVisualMesh.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,15 @@ void ASofaVisualMesh::updateMesh()
8383
std::string nodeUniqID = std::string(TCHAR_TO_UTF8(*m_uniqueNameID));
8484

8585
// Get number of vertices
86-
int nbrV = m_sofaAPI->getNbVertices(nodeUniqID);
86+
int nbrV = m_sofaAPI->getNbVertices(nodeUniqID); // -83 == SAPAPI_INVALID_MESH_ID
87+
88+
if (nbrV == 0)
89+
return;
90+
else if (nbrV < 0)
91+
{
92+
UE_LOG(SUnreal_log, Error, TEXT("## ASofaVisualMesh::updateMesh: %s | getNbVertices returns: %d"), *this->GetName(), nbrV);
93+
return;
94+
}
8795

8896
// Get the different buffers
8997
float* sofaVertices = new float[nbrV * 3];
@@ -112,6 +120,9 @@ void ASofaVisualMesh::updateMesh()
112120
}
113121
}
114122
mesh->UpdateMeshSection(0, vertices, normals, TArray<FVector2D>(), TArray<FColor>(), TArray<FProcMeshTangent>());
123+
124+
delete[] sofaVertices;
125+
delete[] sofaNormals;
115126
}
116127

117128

@@ -145,7 +156,7 @@ void ASofaVisualMesh::createMesh()
145156
float* sofaNormals = new float[nbrV*3];
146157
float* sofaTexCoords = new float[nbrV * 2];
147158
int* sofaTriangles = new int[nbrTri*3];
148-
int* sofaQuads = new int[nbrQuads * 3];
159+
int* sofaQuads = new int[nbrQuads * 4];
149160

150161
// Get the different buffers
151162
m_sofaAPI->getVPositions(nodeUniqID, sofaVertices);

0 commit comments

Comments
 (0)