Skip to content

Commit

Permalink
Flush stuff pending on visual server thread when exiting, fixes #24669
Browse files Browse the repository at this point in the history
  • Loading branch information
reduz committed Mar 1, 2019
1 parent 856c36c commit abbca3b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions editor/editor_resource_preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -438,6 +445,7 @@ EditorResourcePreview::EditorResourcePreview() {
preview_sem = Semaphore::create();
order = 0;
exit = false;
exited = false;
}

EditorResourcePreview::~EditorResourcePreview() {
Expand Down
3 changes: 2 additions & 1 deletion editor/editor_resource_preview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit abbca3b

Please sign in to comment.