Notifications
Clear all

[Closed] Action on script crash

I work on script which have to block scene redraw when operation take place like:
suspendEditing which:#modify
disableSceneRedraw()

The code it self it`s pretty complex and sometimes crashes whitout no apparent reason and ui is still blocked, what make max useless. Of Course I could just tape :
resumeEditing()
enableSceneRedraw()
completeRedraw()
but for ordinary max user it will be very frustrating.
Is there any way to do anything like:
If script crashed then do …
It would be great.

3 Replies

for an ordinary max user the script should not crash or crash without exception. it’s not a good practice but you can put unstable part of your code into try/catch expression

There is no way to “magically un-crash” Max or to run a piece of code whenever Max crashes.

However what you can do is to run your code in a Try() Catch() expression. Doing this, the script will try to run the code inside the Try() expression and if something goes wrong it will stop the execution and “jump” to the catch() expression without crashing, and run the code inside it.

The first thing I would do is to identify where the problem is. Without knowing this, it will be very hard to find a solution, and running everything in a Try() Catch() expression will not only make your code a pain to read/write, but also will slow it down.

Once you have identified the problem you can see if there is a solution and if it is hard to find you can use Try() Catch() just in that part of the code.

Also make sure that you can safely use suspendEditing(). Some modifiers might crash when using it.

(
 	delete objects
 	node = converttopoly (box())
 	select node
 	
 	try
 	(
 		suspendediting()
 		for j = 1 to node.numverts do polyop.deleteverts node j
 		resumeediting()
 	)
 	catch
 	(
 		resumeediting()
 		messagebox (getcurrentexception())
 	)
 )

thanks Danis, I know good code should`t crash but how can you make 100% bullet proof code in max script where sometimes I get max crash more then 50 times per day, no jokes, not every day but it happen.

thanks PolyTools3D, I like try and catch method however I was thinking more about something like 3dsmax “error raport” system – you have application error and from this point application or some of it module is aware it crashed.

I saw somewhere then you can make some action when max popup will occurs by popup content, but I can`t found it. The example of this is when you can silent some popup like “missing uvw” etc so
I thought maybe I could catch “Maxscript error” popup event somehow.