error msg: attempt to access deleted nodes

error msg: attempt to access deleted nodes

Anonymous
Not applicable
851 Views
5 Replies
Message 1 of 6

error msg: attempt to access deleted nodes

Anonymous
Not applicable
This block of codes intents to create a object which describes the geometry informations of traffice symbol lines, including the width ,the length, the spacing between to short lines, make polygon copys of the lines,and keep the polygon copys(as an array) as a attribute so that I can access the type conveniently.

My first language is not English, apologize for my poor expression.
Anyway , codes talk:


struct trafficLine
(
name,
width = 0.15,
length,
spacing,
guideLines = #(),
Polys = #(),

fn makePolys =
(
if polys.count != 0 then for i in polys do delete i

polys = #()

tempPart = plane width:length length:width name:(uniqueName name) lengthsegs:1 widthSegs:1 mapcoords:on

for i in guideLines do
(
currentPoly = MakeStripPoly i tempPart spacing 0.5 off
--function "MakeStripPoly" will return a polygon object made by given parameters.

append polys currentPoly
)
),

fn resetGuidelines =
(
guideLines = #()
),

fn resetPolys =
(
polys = #()
),

fn nameGuideLines =
(
for i in guideLines do i.name = uniqueName (name + "_GuideLine")
)
)




then I run these codes:

a = trafficLine name:"haha" guideLines:(for i in selection where canConvertTo i splineshape collect i) width:0.15 length:2 spacing:4

a.width = 3
a.length = 5
a.spacing = 4
--a.setGuidelinesBySelection()

a.makePolys()



then when I run this line: select a.polys
It says "attempt to access deleted nodes".

I prefer that when I change a's property and run a.makePolys() again ,it will CHANGE the Polys into a new version but not CREATE a new version of polys. But however, the "deleted Nodes" thing now is getting in my way.

Any help?
0 Likes
852 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
I tried to debug your code, but not having the original version of MakeStripPoly(), I just created a simple box as a place holder, but got no errors whatsoever (and could not see any obvious mistake by looking at the code either).
Make sure the deletion of the object does NOT happen within the MakeStripPoly() function. After all, the i and tempPart variables appear to be passed to the makeStripPoly() function as arguments and the result is currentPoly. It is quite possible that the value of currentPoly could become invalid within the makeStripPoly() which we have not seen yet.

Can you add some debug prints after the line 'append polys currentPoly' to see what is in the polys array, and also before the line 'if polys.count != 0 then for i in polys do delete i'. Keep in mind that if a node is already deleted, it is NOT gone from the scene yet because the Undo buffer is keeping a record of it. Thus, if a.polys contains a deleted node, it is still an entry in the array but cannot be deleted again and will throw the '-- Runtime error: Attempt to access deleted scene object' message.

One way to overcome this is to say

for i in polys where isValidNode i do delete i


Note that you don't need the IF test before that line because if polys is #(), in other words if polys.count == 0, no loop will be performed anyways...
0 Likes
Message 3 of 6

Anonymous
Not applicable
"I tried to debug your code, but not having the original version of MakeStripPoly(), I just created a simple box as a place holder, but got no errors whatsoever (and could not see any obvious mistake by looking at the code either)."
---------------------------------------------------------------------------------
My 3ds max Version is 8.0. Maybe it has something to do with the version, I wonder.


"Keep in mind that if a node is already deleted, it is NOT gone from the scene yet because the Undo buffer is keeping a record of it."
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
In fact, "how to make 'deleted nodes' really GONE" is exactly what I'm trying to figure out by asking this question. Any advice about that?


Anyway, thank you, Bobo. You are the best! ( I'm a big fan of you! )
0 Likes
Message 4 of 6

Anonymous
Not applicable
PS:
Replace the function "makeStripPoly()" with box() is fine. There isn't any related deletion happening inside.
0 Likes
Message 5 of 6

Anonymous
Not applicable
"I tried to debug your code, but not having the original version of MakeStripPoly(), I just created a simple box as a place holder, but got no errors whatsoever (and could not see any obvious mistake by looking at the code either)."
---------------------------------------------------------------------------------
My 3ds max Version is 8.0. Maybe it has something to do with the version, I wonder.


"Keep in mind that if a node is already deleted, it is NOT gone from the scene yet because the Undo buffer is keeping a record of it."
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
In fact, "how to make 'deleted nodes' really GONE" is exactly what I'm trying to figure out by asking this question. Any advice about that?


Anyway, thank you, Bobo. You are the best! ( I'm a big fan of you! )


If you have an array containing nodes and you delete half of them from the scene, the array will keep its size, but in place of all previously existing nodes you will have DeletedSceneObject placeholders. Since your code was just attempting to make sure NO nodes are left in the scene from the previous run, the line I suggested should have worked. It deletes all nodes that are NOT deleted yet, while skipping all already deleted ones. Once you have done that, you redefine the array to #() anyway, so the deleted node references would be gone from the array, and from the scene and only potentially exist in the Undo Buffer, which you could clear, but that is usually a bad idea.
Calling the Garbage Collector using gc() will clear the Undo Buffer as a side effect and it removes any references to deleted nodes. You can also call clearUndoBuffer(). In both cases, you will lose all undo records and won't be able to undo anything done before that point.

If you wanted to PURGE the array of the deleted nodes and keep all other non-deleted nodes in it, you would say:

theArray = for o in theArray where isValidNode o collect o


So if theArray contained 10 existing and 10 deleted node references, the above line would SHRINK it to the 10 existing nodes, removing any references to the deleted ones.
0 Likes
Message 6 of 6

Anonymous
Not applicable
I have tried my code again.this time it works fine, like you said.

It turns out that when I was debugging my code first time, I have manually deleted one of the mumbers of "polys" (which is the real cause of the confusing error message.) I then made sure after the deletion of old version, the array "Polys" would be empty again. But the message kept jumping out , which brought serious panic.

However, your codes will work even when one of the polys be deleted manually, much healther than It used to be. Thanks!
0 Likes