PDA

View Full Version : Attempting to access deleted trimesh


Stillwell
06-17-2006, 02:49 AM
Hello there!
I've written a function that tries and succesfully calculates the total number of vertices in a scene and it works fine, until I try to put an Edit Poly/Mesh modifier on any of the scene object. Then, it gives me this error:

MAXSCRIPT redrawviews Callback exception
--Runtime error: Attempt to access deleted Trimesh.

It seems like the mesh information is obsolete and my function can't access the information, but I don't know how to reset the mesh information, or tell the script to stop looking where it shouldn't.

Any help would be appreciated.

Thanks!

EDIT: I thought posting my function would probably be useful?


fn getTotalSceneVerticesAsString =
(
tsv = 0
for o in $geometry do
(
tsv += o.mesh.numVerts
)
ss = stringstream ""
format "%" tsv to:ss
return ss as string
),


The error then highlights tsv += o.mesh.numVerts.

Bobo
06-17-2006, 04:30 AM
Your function is also leaking memory. Each time you call .mesh, a new copy of the TriMesh is created and only cleared if you perform manual garbage collection.

Try this version and see if it has the same issue with added modifiers (it should not).
It also deletes the TriMesh from memory after each iteration, and makes sure no targetObjects (which are GeometryClass) are included (they would crash the function as they have no mesh to return).

Finally, you don't need to create a stringstream in order to return a string...

fn getTotalSceneVerticesAsString =
(
tsv = 0
for o in geometry where classof o != TargetObject do
(
theMesh = snapshotasmesh o
tsv += theMesh.numverts
delete theMesh
)
tsv as string
)

Stillwell
06-18-2006, 05:25 AM
Thanks Bobo, that worked great.

CGTalk Moderation
06-18-2006, 05:25 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.