Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5800

Some learnings on developing a fast Python/C++ script for importing a mesh from an .OBJ file

$
0
0

In the C++ code below, a new_mesh is created using ON_Mesh and then populated with vertices and faces and it all works fine. But if new_mesh turns out not to be valid, then should new_mesh be deleted as shown in the last line or does the usage of ON_Mesh take care of this? That is, when this procedure exits, will ON_Mesh will remove the memory allocated for new_mesh?

ON_Mesh *new_mesh = new ON_Mesh();

// Add vertices and faces in this space.

new_mesh->Compact();
valid = new_mesh->IsValid();
// If mesh is not valid, try removing degenerate faces.
if (!valid) {
	new_mesh->CullDegenerateFaces();
	new_mesh->Compact();
	valid = new_mesh->IsValid();
}
// Add new mesh to Rhino document.
if (valid) { meshObject->SetMesh(new_mesh); }
// Is next line needed? Or does using ON_Mesh eliminate this need?
else delete new_mesh;

I have very few memory leak problems in my C++ code and want to make sure this is not a contributor.

Regards,
Terry.

24 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 5800

Trending Articles