summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor/editor_resource_preview.cpp8
-rw-r--r--editor/editor_resource_preview.h3
2 files changed, 10 insertions, 1 deletions
diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp
index e0c292dc87..9345ea6b6f 100644
--- a/editor/editor_resource_preview.cpp
+++ b/editor/editor_resource_preview.cpp
@@ -313,6 +313,8 @@ void EditorResourcePreview::_thread() {
preview_mutex->unlock();
}
}
+
+ exited = true;
}
void EditorResourcePreview::queue_edited_resource_preview(const Ref<Resource> &p_res, Object *p_receiver, const StringName &p_receiver_func, const Variant &p_userdata) {
@@ -420,11 +422,16 @@ void EditorResourcePreview::check_for_invalidation(const String &p_path) {
void EditorResourcePreview::start() {
ERR_FAIL_COND(thread);
thread = Thread::create(_thread_func, this);
+ exited = false;
}
void EditorResourcePreview::stop() {
if (thread) {
exit = true;
preview_sem->post();
+ while (!exited) {
+ OS::get_singleton()->delay_usec(10000);
+ VisualServer::get_singleton()->sync(); //sync pending stuff, as thread may be blocked on visual server
+ }
Thread::wait_to_finish(thread);
memdelete(thread);
thread = NULL;
@@ -438,6 +445,7 @@ EditorResourcePreview::EditorResourcePreview() {
preview_sem = Semaphore::create();
order = 0;
exit = false;
+ exited = false;
}
EditorResourcePreview::~EditorResourcePreview() {
diff --git a/editor/editor_resource_preview.h b/editor/editor_resource_preview.h
index c958bfbb74..703ba34e43 100644
--- a/editor/editor_resource_preview.h
+++ b/editor/editor_resource_preview.h
@@ -90,7 +90,8 @@ class EditorResourcePreview : public Node {
Mutex *preview_mutex;
Semaphore *preview_sem;
Thread *thread;
- bool exit;
+ volatile bool exit;
+ volatile bool exited;
struct Item {
Ref<Texture> preview;