Skip to content

Commit

Permalink
[Editor] Fix threading problems with TileMap preview
Browse files Browse the repository at this point in the history
(cherry picked from commit dbcd82b)
  • Loading branch information
AThousandShips authored and Riordan-DC committed Aug 15, 2024
1 parent 347e908 commit e864293
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions editor/plugins/tiles/tiles_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ void TilesEditorUtils::_thread_func(void *ud) {
}

void TilesEditorUtils::_thread() {
CallQueue queue;
MessageQueue::set_thread_singleton_override(&queue);

pattern_thread_exited.clear();
while (!pattern_thread_exit.is_set()) {
pattern_preview_sem.wait();
Expand Down Expand Up @@ -130,6 +133,8 @@ void TilesEditorUtils::_thread() {
// Add the viewport at the last moment to avoid rendering too early.
callable_mp((Node *)EditorNode::get_singleton(), &Node::add_child).call_deferred(viewport, false, Node::INTERNAL_MODE_DISABLED);

MessageQueue::get_singleton()->flush();

RS::get_singleton()->connect(SNAME("frame_pre_draw"), callable_mp(const_cast<TilesEditorUtils *>(this), &TilesEditorUtils::_preview_frame_started), Object::CONNECT_ONE_SHOT);

pattern_preview_done.wait();
Expand All @@ -142,7 +147,11 @@ void TilesEditorUtils::_thread() {
viewport->queue_free();
}
}

MessageQueue::get_singleton()->flush();
}

MessageQueue::get_singleton()->flush();
pattern_thread_exited.set();
}

Expand Down

0 comments on commit e864293

Please sign in to comment.