I have successfully created a UI form for my plugin, it loads fine and works as expected. Now I'm working on the core logic. It has some heavy task that user can launch from UI.
Being a good citizen, I don't want to freeze the UI, so I tried some standard multithreading techniques with QRunnable and also QThread. I could not find anything related to "thread" in Reallusion's wiki, so I tried some examples I found on the Internet.
Unfortunately, it always crashes iClone as soon as I start a thread. I have created a simplified minimal example script that crashes iClone by mere attempting to launch a thread that does only print().
To reproduce the issue, save the following code snippet as threads.py file as run it as usual with Script->Load plugin and then go to Plugins -> Python Samples -> Run thread.
import RLPy
import PySide2
from PySide2 import *
from PySide2.shiboken2 import wrapInstance
from PySide2.QtCore import *
class DummyWorker(QThread) :
def run(self) :
print(f"worker finished.")
my_thread = None
def initialize_plugin() :
global my_thread
# Add menu
ic_dlg = wrapInstance(int(RLPy.RUi.GetMainWindow()), QtWidgets.QMainWindow)
plugin_menu = ic_dlg.menuBar().findChild(QtWidgets.QMenu, "pysample_menu")
if (plugin_menu == None):
plugin_menu = wrapInstance(int(RLPy.RUi.AddMenu("Python Samples", RLPy.EMenu_Plugins)), QtWidgets.QMenu)
plugin_menu.setObjectName("pysample_menu")
menu_actions = plugin_menu.actions()
for a in menu_actions :
if a.text() == "Run thread":
plugin_menu.removeAction(a)
hello_world_action = plugin_menu.addAction("Run thread")
hello_world_action.triggered.connect(run_thread)
my_thread = DummyWorker()
def run_thread() :
RLPy.RUi.ShowMessageBox("Python Plugin", "Will launch a thread, keep fingers crossed...", RLPy.EMsgButton_Ok)
my_thread.start()
def run_script() :
initialize_plugin()
For me, it freezes iClone for a few seconds, and then iClone crashes. I couldn't even find any meaningful crash logs in appdata Reallusion folder - it's some encoded garbage like 61CEA8EAACB90F063C0DE4C ....
Has anyone any ideas? What is proper, safe way to run a heavy background task in iClone Python environment?