|
41 | 41 | #include "editor/editor_settings.h" |
42 | 42 | #include "editor/editor_string_names.h" |
43 | 43 | #include "scene/resources/image_texture.h" |
| 44 | +#include "servers/rendering/rendering_server_default.h" |
44 | 45 |
|
45 | 46 | bool EditorResourcePreviewGenerator::handles(const String &p_type) const { |
46 | 47 | bool success = false; |
@@ -338,6 +339,20 @@ void EditorResourcePreview::_thread() { |
338 | 339 | exited.set(); |
339 | 340 | } |
340 | 341 |
|
| 342 | +void EditorResourcePreview::_idle_callback() { |
| 343 | + if (!singleton) { |
| 344 | + // Just in case the shutdown of the editor involves the deletion of the singleton |
| 345 | + // happening while additional idle callbacks can happen. |
| 346 | + return; |
| 347 | + } |
| 348 | + |
| 349 | + // Process preview tasks, trying to leave a little bit of responsiveness worst case. |
| 350 | + uint64_t start = OS::get_singleton()->get_ticks_msec(); |
| 351 | + while (!singleton->queue.is_empty() && OS::get_singleton()->get_ticks_msec() - start < 100) { |
| 352 | + singleton->_iterate(); |
| 353 | + } |
| 354 | +} |
| 355 | + |
341 | 356 | void EditorResourcePreview::_update_thumbnail_sizes() { |
342 | 357 | if (small_thumbnail_size == -1) { |
343 | 358 | // Kind of a workaround to retrieve the default icon size. |
@@ -441,27 +456,36 @@ void EditorResourcePreview::check_for_invalidation(const String &p_path) { |
441 | 456 | } |
442 | 457 |
|
443 | 458 | void EditorResourcePreview::start() { |
444 | | - if (DisplayServer::get_singleton()->get_name() != "headless") { |
| 459 | + if (DisplayServer::get_singleton()->get_name() == "headless") { |
| 460 | + return; |
| 461 | + } |
| 462 | + |
| 463 | + if (RSG::texture_storage->can_create_resources_async()) { |
445 | 464 | ERR_FAIL_COND_MSG(thread.is_started(), "Thread already started."); |
446 | 465 | thread.start(_thread_func, this); |
| 466 | + } else { |
| 467 | + SceneTree *st = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop()); |
| 468 | + ERR_FAIL_NULL_MSG(st, "Editor's MainLoop is not a SceneTree. This is a bug."); |
447 | 469 | } |
448 | 470 | } |
449 | 471 |
|
450 | 472 | void EditorResourcePreview::stop() { |
451 | | - if (thread.is_started()) { |
452 | | - exiting.set(); |
453 | | - preview_sem.post(); |
| 473 | + if (RSG::texture_storage->can_create_resources_async()) { |
| 474 | + if (thread.is_started()) { |
| 475 | + exiting.set(); |
| 476 | + preview_sem.post(); |
454 | 477 |
|
455 | | - for (int i = 0; i < preview_generators.size(); i++) { |
456 | | - preview_generators.write[i]->abort(); |
457 | | - } |
| 478 | + for (int i = 0; i < preview_generators.size(); i++) { |
| 479 | + preview_generators.write[i]->abort(); |
| 480 | + } |
458 | 481 |
|
459 | | - while (!exited.is_set()) { |
460 | | - OS::get_singleton()->delay_usec(10000); |
461 | | - RenderingServer::get_singleton()->sync(); //sync pending stuff, as thread may be blocked on rendering server |
462 | | - } |
| 482 | + while (!exited.is_set()) { |
| 483 | + OS::get_singleton()->delay_usec(10000); |
| 484 | + RenderingServer::get_singleton()->sync(); //sync pending stuff, as thread may be blocked on rendering server |
| 485 | + } |
463 | 486 |
|
464 | | - thread.wait_to_finish(); |
| 487 | + thread.wait_to_finish(); |
| 488 | + } |
465 | 489 | } |
466 | 490 | } |
467 | 491 |
|
|
0 commit comments