I use 3 separate NMesh objects to call three times a subroutine
with different parameters, then I collect all mesh data
in a fourth mesh object.
This fourth is the only for wich PutRaw is invoked.
All this is actually within a subroutine
More or less:
MeshQ1 = NMesh.GetRaw()
MeshQ2 = NMesh.GetRaw()
MeshQ3 = NMesh.GetRaw()
QuadMesh(v1,va1,va4,va3,N,MeshQ1)
QuadMesh(v2,va2,va4,va1,N,MeshQ2)
QuadMesh(v3,va3,va4,va2,N,MeshQ3)
MeshT = NMesh.GetRaw()
for v in MeshQ1.verts:
MeshT.verts.append(v)
for f in MeshQ1.faces:
MeshT.faces.append(f)
for v in MeshQ2.verts:
MeshT.verts.append(v)
for f in MeshQ2.faces:
MeshT.faces.append(f)
for v in MeshQ3.verts:
MeshT.verts.append(v)
for f in MeshQ3.faces:
MeshT.faces.append(f)
NMesh.PutRaw(MeshT)
Except that MeshT is actually between the arguments of this subroutine and the PutRaw happens in the caller.
Question is:
Those three meshes MeshQ1,MeshQ2 and MeshQ3 needs to be explicitely destroyed at the end of the subroutine
to prevent memory leaks?
And if yes, how?
THis subroutine is going to be called 8 to 20 times in a row and meshes can be quite big, and user can call it more than once…
Thanx, I’ll give both suggestions (del and sortening) a try.
In any case script runs the first time, and crashes Blender on second run. Furthermore newely created objecs are single sided (?) usually with AutoSmooth on and sometimes SubSurfed…
Blender python objects usually have a pointer to a datablock of info (malloc() allocated), but NMesh is a little different.
Calling getRaw() without a parameter will not link the mesh datablock (malloc() allocated) to the python mesh you created (this is normal behavior). Instead it will create a python representation of the data, and set the python object’s data pointer to NULL.
Calling update() on a python mesh creates a new datablock which represents the python mesh’s values.
Also calling PutRaw() will free the datablock (if any) pointed to and the write/rewrite it using the ‘python mesh’ data.
So in your case you are simply overwriting the python mesh’s data and there have been no calls to malloc() to allocate data. (at least until you call putRaw())
As a slide note heres a little blip about blenders gc:(copies out of datablock.c)
" *Blender Objects have their own ‘reference counting’, e.g. a Mesh datablock used by two Objects has a user count of 2. Datablocks with user count of 0 are not saved to Disk – this is the current way Blender does
‘garbage collection’ Therefore, an object should normally not be deleted by Python, but rather unlinked from its parent object. …"
Setting modes(from the python API):
This might be a better way :). Call myMesh.setMode(). Parameters: “NoVNormalsFlip”, “TwoSided”, “AutoSmooth”, “SubSurf”