Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Crash after Delete Node

Crash after Delete Node

Anonymous
Not applicable
927 Views
2 Replies
Message 1 of 3

Crash after Delete Node

Anonymous
Not applicable

I've experienced Max to crash after deleting objects. The script pops up a rollout, and pressing a button calls a function to delete certain objects. Before adding the UI the script worked fine in isolation. I have checked out this example, and since revised the code to append the objects to an array and then to delete that instead. Which, so far, seems stable.

 

I was just wondering why the problem was occuring. Is looping over a for x in geometry .. do delete x, just a bad idea??

0 Likes
928 Views
2 Replies
Replies (2)
Message 2 of 3

Steve_Curley
Mentor
Mentor

Is looping over a for x in geometry .. do delete x, just a bad idea??


I personally wouldn't do that - I'd treat the collection as an array and work DOWN not UP.
If you really mean the built-in "geometry" Collection, or indeed any Collection of objects, then to delete everyting in the Collection you simply "delete [collection name]" - it's a "mapped function" which will do the job without error.
To do it manually use
for idx = collectionname.count to 1 by -1 do delete collectionname[idx]
Would have to see the whole script, including the UI, to work out what's really causing the crash. Trying to reference one of then objects which no longer exists would certainly cause a problem.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 3

blakestone
Collaborator
Collaborator

Personally I collect what I want to delete into an array and then delete it afterwards as I've found many scenarios, like yourself, where the script will fail because it's trying to access something which no longer exists in the scene.

Here is an example I use to avoid script errors:

 

(
  local delete_array = #()
	
  with undo on									-- undo on
  (
    for var in geometry where classOf var == editable_poly do	-- loop through all editable poly objects
    (
        if (random 0 1) == 1 then append delete_array var		-- 0 = skip object | 1 = collect object to array	
    )
		
    print delete_array								-- print all objects to delete
    print ("Total Objects: " + delete_array.count as string)		-- print summary	
		
    delete delete_array								-- delete all scene object
  )
)

 

example.gif

--------------------------------------------------------------------------------------
Technical 3D Graphic Artist
Autodesk 3dsMax 2015 - Service Pack 4
--------------------------------------------------------------------------------------
0 Likes