[pymxs] Threading and Modify tab == CRASH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello!
pymxs includes a specific context (mxstoken) that allow us to synchronize calls between different worker threads.
From documentation:
You cannot call pymxs.runtime commands directly on a worker thread, as this will cause a runtime exception. However, pymxs has a mxstoken() function to support multi-threading by providing a synchronization mechanism between worker threads.And here and example of its usage:
https://help.autodesk.com/view/3DSMAX/2017/ENU/?guid=__py_ref_demo_m_x_s_token_8py_example_html
It works fine, but I have found that 3ds Max crashes if I try to call a function from pymxs.runtime that interacts with 3ds Max modify panel. Super basic code:
import pymxs
import threading
import time
def callMXSEntry():
with pymxs.mxstoken():
pymxs.runtime.modPanel.addModToSelection(pymxs.runtime.Unwrap_UVW())
def main():
evt = threading.Event()
t1 = threading.Thread(target=callMXSEntry)
t1.start()
main()
If you execute this code, 3ds max will crash (tested in 3ds Max 2018 and 2020).
I can imagine that this is happening because that call tries to update Modify Tab UI and 3ds Max UI can only be updated/refreshed in 3ds Max main thread but I'm a not sure about it.
Do you know a workaround/solution for this?
Thank you so much!