Python script crash on medium and big max file

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I was stress testing a Python Qt tool for 3ds Max with different asset and 3ds Max crashed.
I've done some investigation and it appears that the tool only runs on "small file" (with less than 100 000 polys).
For medium (polys < 1 000 000) and large files (polys > 1 000 000) 3ds Max crash with one of those lovely pop-up :
With of course no information and then the exit of 3ds Max.
After some research and some help from the 3ds Max Discord, I found this link (https://knowledge.autodesk.com/support/3ds-max/troubleshooting/caas/sfdcarticles/sfdcarticles/3ds-Ma...) and decided to disable my Qt GUI.
After that I discover 2 exceptions :
- One while doing some geometry test using STL check and XView (those two elements are really slow with high poly assets by the way) :
- Known system exception
- Address: 0xe54ac699; nCode: 0x00000000C0000005
- Desc: EXCEPTION_ACCESS_VIOLATION The thread tried to read from or write to a virtual address for which it does not have the appropriate access.
- Read of Address: 0xFFFFFFFFFFFFFFFF
- This one (I love it) which can appear at different time but mainly while testing one by one all objects/layer in my scene : "Runtime error: Unknown exception thrown executing script"
The weirdest part is that after one of those two exceptions appear, if I re-run the same script no exception will appear and the script do what I wanted until I close and re-open 3ds Max.
Based on that I've created the best worst solution for this problem. I want to show you this solution, with the hope that someone more qualified than me will give me a better solution.
The script is in python but those two exceptions are 3ds Max/MAXScript Exception so I must catch them in MAXScript (I found no wrapper for that stuff in python doc).
So here is the code snippet in python that create a MAXScript Try/Catch around another python function :
import pymxs
from pymxs import runtime as rt
beginMAXScriptCode = "try ( python.execute \""
endMAXScriptCode = "\" )\ncatch\n(\npython.execute \"print('The MAXScript error catched: ', rt.getCurrentException())\")"
pythonCode = "print('Python code that has a exception in MAXScript')"
rt.execute(beginMAXScriptCode + pythonCode + endMAXScriptCode)
In my case, it was more diffcult than that because the code that throws those exceptions is in a class and the main python script doesn't share his state and variables with the python script in the MAXScript code so I have to create a singleton class to share all the informations between those two code parts.
This solution is working for me (even with my Qt GUI) but it's ugly and probably unstable so if you have any idea to do it better please let me know.
If you have any question I'll be glad to answer you.
By the way I'm using 3ds Max 2020 so if there is something in 3ds Max 2021 that correct those problems please tell me too.
Thanks for your attention