diff options
author | Brian Semrau <brian.semrau@gmail.com> | 2021-11-05 02:43:03 -0400 |
---|---|---|
committer | Brian Semrau <brian.semrau@gmail.com> | 2021-11-05 12:58:14 -0400 |
commit | a90e318a1914748cfb2943b91d6e1d8b9ddd7d60 (patch) | |
tree | 8519a646ee3c443b0081242082180ee701d1d9fb /editor/plugins/tiles/tiles_editor_plugin.cpp | |
parent | 56cfebbe98ef18d91b891dbbde96081343d5b4cc (diff) |
Fix previews sometimes displaying wrong/blank image
Diffstat (limited to 'editor/plugins/tiles/tiles_editor_plugin.cpp')
-rw-r--r-- | editor/plugins/tiles/tiles_editor_plugin.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
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<TilesEditorPlugin *>(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<TilesEditorPlugin *>(this), &TilesEditorPlugin::_pattern_preview_done)); + RS::get_singleton()->connect(SNAME("frame_pre_draw"), callable_mp(const_cast<TilesEditorPlugin *>(this), &TilesEditorPlugin::_preview_frame_started), Vector<Variant>(), Object::CONNECT_ONESHOT); - while (!pattern_preview_done.is_set()) { - OS::get_singleton()->delay_usec(10); - } + pattern_preview_done.wait(); Ref<Image> image = viewport->get_texture()->get_image(); Ref<ImageTexture> image_texture; |