From a90e318a1914748cfb2943b91d6e1d8b9ddd7d60 Mon Sep 17 00:00:00 2001 From: Brian Semrau Date: Fri, 5 Nov 2021 02:43:03 -0400 Subject: Fix previews sometimes displaying wrong/blank image --- editor/plugins/tiles/tiles_editor_plugin.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'editor/plugins/tiles/tiles_editor_plugin.cpp') diff --git a/editor/plugins/tiles/tiles_editor_plugin.cpp b/editor/plugins/tiles/tiles_editor_plugin.cpp index 8e2c16906d..47dfc57b0f 100644 --- a/editor/plugins/tiles/tiles_editor_plugin.cpp +++ b/editor/plugins/tiles/tiles_editor_plugin.cpp @@ -47,8 +47,12 @@ TilesEditorPlugin *TilesEditorPlugin::singleton = nullptr; +void TilesEditorPlugin::_preview_frame_started() { + RS::get_singleton()->request_frame_drawn_callback(callable_mp(const_cast(this), &TilesEditorPlugin::_pattern_preview_done)); +} + void TilesEditorPlugin::_pattern_preview_done() { - pattern_preview_done.set(); + pattern_preview_done.post(); } void TilesEditorPlugin::_thread_func(void *ud) { @@ -112,12 +116,9 @@ void TilesEditorPlugin::_thread() { // Add the viewport at the lasst moment to avoid rendering too early. EditorNode::get_singleton()->add_child(viewport); - pattern_preview_done.clear(); - RS::get_singleton()->request_frame_drawn_callback(callable_mp(const_cast(this), &TilesEditorPlugin::_pattern_preview_done)); + RS::get_singleton()->connect(SNAME("frame_pre_draw"), callable_mp(const_cast(this), &TilesEditorPlugin::_preview_frame_started), Vector(), Object::CONNECT_ONESHOT); - while (!pattern_preview_done.is_set()) { - OS::get_singleton()->delay_usec(10); - } + pattern_preview_done.wait(); Ref image = viewport->get_texture()->get_image(); Ref image_texture; -- cgit v1.2.3