Lessons from building and supporting TerraScoop on 3ds Max 2022-2027 (PySide2 and PySide6), each one a real failure. They apply to any Python + Qt tool in Max. The starter templates already follow them.
Users whose Max crashes when a tool starts can usually send only MaxPkg’s log, which mirrors the MAXScript Listener.
startguard.py): before every start step (settings, scale, theme, window, geometry, show) write the
step to logs/start-<host>.json; write ready once the window works (and stopped / failed on close or a Python
error). A start that finds an unfinished step knows Max died during it.qtmax hotkey
hooks, following Max’s window), the window centred instead of restored. A new version tries the normal start again.logs/crash-<host>.log with a session mark at each start, all threads. Enable it after the
guard has read the previous session’s tail.Garbage-collecting means Python’s garbage
collector met a broken object; the frames below are only where the collection happened to run (an import, a
findChildren), and disabling features just moves the crash.Max 2024 (PySide2 5.15.1 on Python 3.10) died at the first full collection after a large tool window was built; the same Python and PySide2 outside Max did not, even with a collection every 300 ms. The broken object comes from inside Max.
Garbage-collecting): gc.disable() at the very start of start(); on close gc.freeze() then gc.enable(), so no
later collection walks the objects that existed (including the broken one). Reference counting still frees almost
everything; only cyclic garbage made meanwhile stays.gcprobe.run() from the Listener (python.execute "from mytool import gcprobe; gcprobe.run()", tool open) walks every
tracked object and its references like a collection does, and writes the type it is at into an mmap’d file first, so a
crash still names the object; the next start’s report includes it.QGuiApplication.screens() (live_screens, screen_at, work_area,
primary_work_area), skip wrappers that raise, keep no QScreen objects, and fall back to a Full HD area.widget.style() can be dead (another tool replaced the application style, Max 2026): never call
style().unpolish/polish; repolish(widget) re-applies the widget’s own style sheet instead, and puts back the
interface-size font that polishing takes away (interface size).deleteLater, a Python wrapper may outlive its C++ object: check shiboken.isValid (is_valid) before late
callbacks touch widgets.3ds Max filters events for the whole application, before a widget’s own event filters:
qt_compat.own_keyboard on itself and its children when it shows
(DisableMaxAcceleratorsOnFocus): the main window, dialogs, the calendar, the colour picker and its pipette, the
lightbox and menus. A popup created later than its window needs its own call.Qt’s own tooltip window, rounded by a mask. To round the plain tooltips, a first try set a window mask on Qt’s
tooltip label (qtooltip_label, a private QTipLabel) and installed an event filter object on it. 3ds Max 2022
died with an access violation in the next QToolTip.showText (the faulthandler dump named that line): Qt deletes
and recreates that label on its own schedule. Never touch Qt’s tooltip window; the tool shows its own Tip
(controls.Tip, see the controls catalog).
QCompleter(model, field), asked it
for its default popup and set it on the field. 3ds Max 2022 (PySide2 5.15.1) died with a heap corruption
(0xc0000374 in ntdll.dll, no Python traceback, no faulthandler dump) in the first event-loop pass after the window
showed, or a moment after the window closed. Every widget built alone in a hidden window was fine; only the whole
window failed. The fix is TerraScoop’s proven pattern: the completer and its model belong to the window
(SearchBox(..., owner=window)), the list view is created in Python and handed over with setPopup, the delegate
is set after it, and the popup gets the style sheet and font when it opens. The trainer then passed every check in
Max 2022 and stayed up after closing.__init__ ends. PySide6 (3ds Max 2027) runs a dialog’s eventFilter while the
base class constructor is still building the title bar, before the subclass has created its own widgets: the
Support and message windows failed to open with “object has no attribute”. In an eventFilter, read the subclass’s
widgets with getattr(self, "name", None), and assign a watched widget to its attribute before
installEventFilter. PySide2 (3ds Max 2022) never showed it, so a check in one Max version is not enough.os.fsync) before and after each step; then build the whole window with sections switched off by halves; then
swap the suspect for a stand-in and switch its parts on one by one. The last marker names the step. Use a Max that
holds no user work for this; a native crash cannot be caught._GilPump), and stops
when the runner is idle. Start every job through JobRunner.submit so the pump starts. No nested processEvents().pymxs, scene, viewport and Qt widget calls stay on the main thread. Workers get plain data; results and progress come
back through a queued signal (_Poster) and are dropped when the session stops or the job was cancelled.python.exe -B -m
package.worker job.pickle with the working directory python/. Not multiprocessing (inside Max sys.executable is
3dsmax.exe and spawn re-imports __main__). Not python.exe package/worker.py by path (the package folder shadows the
standard library: a module named http.py replaced http). Pass the Qt DLL folder and plugin path if the worker uses
Qt; end it with taskkill /F /T on cancel so its own children die too; fall back to threads if no process starts.OMP_WAIT_POLICY=PASSIVE and a thread count per job.qtmax.DisableMaxAcceleratorsOnFocus(widget, True) for the window and every child (again for widgets created later).QWebChannel must have slots only with str arguments and no signals: a published
Signal(dict) / Signal(list) made the channel convert PyObjects recursively until the native stack overflowed and
Max died. Python-facing signals live on a separate, unpublished QObject without a widget parent.inset, no ?. / ??).runJavaScript(code, callback) does not exist: use runJavaScript(code, 0, callback) in both bindings.runJavaScript, not a window grab.mesh vertices: faces: materialIDs: (triangles), hide triangulation diagonals
with setEdgeVis, then convertToPoly (it keeps the hidden diagonals and rebuilds the polygons). polyop.createPolygon
per face is quadratic in Max 2022 (minutes for 30k vertices). Set smoothing groups explicitly (the mesh constructor
defaults to group 1; give sharp parts their own groups).mesh tverts: is silently ignored: apply UVs explicitly (setNumTVerts, setTVert, buildTVFaces, setTVFace).python.execute / MCP are top-level code: wrap them in ( ... ) before using local.
python.execute returns nothing: put results on a known module attribute and read it back.gc() in a user’s scene (it clears the undo history); use gc light:true.QTimer.singleShot(0), and updateSceneMaterialLib() after deleting materials. Running out of
commit memory is an access violation, not a MemoryError: estimate the memory of what will be created and check free
commit plus page-file room before creating millions of triangles; include every generated mesh in the estimate.logs.set_host("max2027")), because faulthandler keeps its file open.python.exe ignores PYTHONPATH: tests insert the package path themselves.sys.exit() / raise SystemExit in code that runs inside Max.resources.py once replaced an existing one).Set-Content -Encoding utf8 writes a BOM; io.open(path, "w", newline=<bad>) truncates the file before it
raises. Edit source files with a proper editor or a script that writes a temporary file and replaces the target.