mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Fix call_on_qt_thread decorator
CURA-6225 Do thread check in the wrapper function, not outside.
This commit is contained in:
parent
ace638ec81
commit
f521fae152
2 changed files with 13 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
import functools
|
||||
import threading
|
||||
|
||||
from cura.CuraApplication import CuraApplication
|
||||
|
@ -6,7 +7,7 @@ from cura.CuraApplication import CuraApplication
|
|||
#
|
||||
# HACK:
|
||||
#
|
||||
# In project loading, when override the existing machine is selected, the stacks and containers that are correctly
|
||||
# In project loading, when override the existing machine is selected, the stacks and containers that are currently
|
||||
# active in the system will be overridden at runtime. Because the project loading is done in a different thread than
|
||||
# the Qt thread, something else can kick in the middle of the process. One of them is the rendering. It will access
|
||||
# the current stacks and container, which have not completely been updated yet, so Cura will crash in this case.
|
||||
|
@ -22,7 +23,13 @@ class InterCallObject:
|
|||
|
||||
|
||||
def call_on_qt_thread(func):
|
||||
@functools.wraps(func)
|
||||
def _call_on_qt_thread_wrapper(*args, **kwargs):
|
||||
# If the current thread is the main thread, which is the Qt thread, directly call the function.
|
||||
current_thread = threading.current_thread()
|
||||
if isinstance(current_thread, threading._MainThread):
|
||||
return func(*args, **kwargs)
|
||||
|
||||
def _handle_call(ico, *args, **kwargs):
|
||||
ico.result = func(*args, **kwargs)
|
||||
ico.finish_event.set()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue