editor_resource_preview.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /**************************************************************************/
  2. /* editor_resource_preview.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "editor_resource_preview.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/io/file_access.h"
  33. #include "core/io/resource_loader.h"
  34. #include "core/io/resource_saver.h"
  35. #include "core/variant/variant_utility.h"
  36. #include "editor/editor_node.h"
  37. #include "editor/editor_paths.h"
  38. #include "editor/editor_settings.h"
  39. #include "editor/editor_string_names.h"
  40. #include "editor/themes/editor_scale.h"
  41. #include "scene/main/window.h"
  42. #include "scene/resources/image_texture.h"
  43. #include "servers/rendering/rendering_server_default.h"
  44. bool EditorResourcePreviewGenerator::handles(const String &p_type) const {
  45. bool success = false;
  46. if (GDVIRTUAL_CALL(_handles, p_type, success)) {
  47. return success;
  48. }
  49. ERR_FAIL_V_MSG(false, "EditorResourcePreviewGenerator::_handles needs to be overridden.");
  50. }
  51. Ref<Texture2D> EditorResourcePreviewGenerator::generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const {
  52. Ref<Texture2D> preview;
  53. if (GDVIRTUAL_CALL(_generate, p_from, p_size, p_metadata, preview)) {
  54. return preview;
  55. }
  56. ERR_FAIL_V_MSG(Ref<Texture2D>(), "EditorResourcePreviewGenerator::_generate needs to be overridden.");
  57. }
  58. Ref<Texture2D> EditorResourcePreviewGenerator::generate_from_path(const String &p_path, const Size2 &p_size, Dictionary &p_metadata) const {
  59. Ref<Texture2D> preview;
  60. if (GDVIRTUAL_CALL(_generate_from_path, p_path, p_size, p_metadata, preview)) {
  61. return preview;
  62. }
  63. Ref<Resource> res = ResourceLoader::load(p_path);
  64. if (!res.is_valid()) {
  65. return res;
  66. }
  67. return generate(res, p_size, p_metadata);
  68. }
  69. bool EditorResourcePreviewGenerator::generate_small_preview_automatically() const {
  70. bool success = false;
  71. GDVIRTUAL_CALL(_generate_small_preview_automatically, success);
  72. return success;
  73. }
  74. bool EditorResourcePreviewGenerator::can_generate_small_preview() const {
  75. bool success = false;
  76. GDVIRTUAL_CALL(_can_generate_small_preview, success);
  77. return success;
  78. }
  79. void EditorResourcePreviewGenerator::_bind_methods() {
  80. GDVIRTUAL_BIND(_handles, "type");
  81. GDVIRTUAL_BIND(_generate, "resource", "size", "metadata");
  82. GDVIRTUAL_BIND(_generate_from_path, "path", "size", "metadata");
  83. GDVIRTUAL_BIND(_generate_small_preview_automatically);
  84. GDVIRTUAL_BIND(_can_generate_small_preview);
  85. }
  86. EditorResourcePreviewGenerator::EditorResourcePreviewGenerator() {
  87. }
  88. void EditorResourcePreviewGenerator::DrawRequester::request_and_wait(RID p_viewport) const {
  89. Callable request_vp_update_once = callable_mp(RS::get_singleton(), &RS::viewport_set_update_mode).bind(p_viewport, RS::VIEWPORT_UPDATE_ONCE);
  90. if (EditorResourcePreview::get_singleton()->is_threaded()) {
  91. RS::get_singleton()->connect(SNAME("frame_pre_draw"), request_vp_update_once, Object::CONNECT_ONE_SHOT);
  92. RS::get_singleton()->request_frame_drawn_callback(callable_mp(const_cast<EditorResourcePreviewGenerator::DrawRequester *>(this), &EditorResourcePreviewGenerator::DrawRequester::_post_semaphore));
  93. semaphore.wait();
  94. } else {
  95. // Avoid the main viewport and children being redrawn.
  96. SceneTree *st = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
  97. ERR_FAIL_NULL_MSG(st, "Editor's MainLoop is not a SceneTree. This is a bug.");
  98. RID root_vp = st->get_root()->get_viewport_rid();
  99. RenderingServer::get_singleton()->viewport_set_active(root_vp, false);
  100. request_vp_update_once.call();
  101. RS::get_singleton()->draw(false);
  102. // Let main viewport and children be drawn again.
  103. RenderingServer::get_singleton()->viewport_set_active(root_vp, true);
  104. }
  105. }
  106. void EditorResourcePreviewGenerator::DrawRequester::abort() const {
  107. if (EditorResourcePreview::get_singleton()->is_threaded()) {
  108. semaphore.post();
  109. }
  110. }
  111. Variant EditorResourcePreviewGenerator::DrawRequester::_post_semaphore() const {
  112. semaphore.post();
  113. return Variant(); // Needed because of how the callback is used.
  114. }
  115. bool EditorResourcePreview::is_threaded() const {
  116. return RSG::texture_storage->can_create_resources_async();
  117. }
  118. void EditorResourcePreview::_thread_func(void *ud) {
  119. EditorResourcePreview *erp = (EditorResourcePreview *)ud;
  120. erp->_thread();
  121. }
  122. void EditorResourcePreview::_preview_ready(const String &p_path, int p_hash, const Ref<Texture2D> &p_texture, const Ref<Texture2D> &p_small_texture, ObjectID id, const StringName &p_func, const Variant &p_ud, const Dictionary &p_metadata) {
  123. {
  124. MutexLock lock(preview_mutex);
  125. uint64_t modified_time = 0;
  126. if (!p_path.begins_with("ID:")) {
  127. modified_time = FileAccess::get_modified_time(p_path);
  128. }
  129. Item item;
  130. item.preview = p_texture;
  131. item.small_preview = p_small_texture;
  132. item.last_hash = p_hash;
  133. item.modified_time = modified_time;
  134. item.preview_metadata = p_metadata;
  135. cache[p_path] = item;
  136. }
  137. Callable(id, p_func).call_deferred(p_path, p_texture, p_small_texture, p_ud);
  138. }
  139. void EditorResourcePreview::_generate_preview(Ref<ImageTexture> &r_texture, Ref<ImageTexture> &r_small_texture, const QueueItem &p_item, const String &cache_base, Dictionary &p_metadata) {
  140. String type;
  141. uint64_t started_at = OS::get_singleton()->get_ticks_usec();
  142. if (p_item.resource.is_valid()) {
  143. type = p_item.resource->get_class();
  144. } else {
  145. type = ResourceLoader::get_resource_type(p_item.path);
  146. }
  147. if (type.is_empty()) {
  148. r_texture = Ref<ImageTexture>();
  149. r_small_texture = Ref<ImageTexture>();
  150. if (is_print_verbose_enabled()) {
  151. print_line(vformat("Generated '%s' preview in %d usec", p_item.path, OS::get_singleton()->get_ticks_usec() - started_at));
  152. }
  153. return; //could not guess type
  154. }
  155. int thumbnail_size = EDITOR_GET("filesystem/file_dialog/thumbnail_size");
  156. thumbnail_size *= EDSCALE;
  157. r_texture = Ref<ImageTexture>();
  158. r_small_texture = Ref<ImageTexture>();
  159. for (int i = 0; i < preview_generators.size(); i++) {
  160. if (!preview_generators[i]->handles(type)) {
  161. continue;
  162. }
  163. Ref<Texture2D> generated;
  164. if (p_item.resource.is_valid()) {
  165. generated = preview_generators.write[i]->generate(p_item.resource, Vector2(thumbnail_size, thumbnail_size), p_metadata);
  166. } else {
  167. generated = preview_generators.write[i]->generate_from_path(p_item.path, Vector2(thumbnail_size, thumbnail_size), p_metadata);
  168. }
  169. r_texture = generated;
  170. if (preview_generators[i]->can_generate_small_preview()) {
  171. Ref<Texture2D> generated_small;
  172. Dictionary d;
  173. if (p_item.resource.is_valid()) {
  174. generated_small = preview_generators.write[i]->generate(p_item.resource, Vector2(small_thumbnail_size, small_thumbnail_size), d);
  175. } else {
  176. generated_small = preview_generators.write[i]->generate_from_path(p_item.path, Vector2(small_thumbnail_size, small_thumbnail_size), d);
  177. }
  178. r_small_texture = generated_small;
  179. }
  180. if (!r_small_texture.is_valid() && r_texture.is_valid() && preview_generators[i]->generate_small_preview_automatically()) {
  181. Ref<Image> small_image = r_texture->get_image();
  182. small_image = small_image->duplicate();
  183. small_image->resize(small_thumbnail_size, small_thumbnail_size, Image::INTERPOLATE_CUBIC);
  184. r_small_texture.instantiate();
  185. r_small_texture->set_image(small_image);
  186. }
  187. break;
  188. }
  189. if (!p_item.resource.is_valid()) {
  190. // Cache the preview in case it's a resource on disk.
  191. if (r_texture.is_valid()) {
  192. // Wow it generated a preview... save cache.
  193. bool has_small_texture = r_small_texture.is_valid();
  194. ResourceSaver::save(r_texture, cache_base + ".png");
  195. if (has_small_texture) {
  196. ResourceSaver::save(r_small_texture, cache_base + "_small.png");
  197. }
  198. Ref<FileAccess> f = FileAccess::open(cache_base + ".txt", FileAccess::WRITE);
  199. ERR_FAIL_COND_MSG(f.is_null(), "Cannot create file '" + cache_base + ".txt'. Check user write permissions.");
  200. _write_preview_cache(f, thumbnail_size, has_small_texture, FileAccess::get_modified_time(p_item.path), FileAccess::get_md5(p_item.path), p_metadata);
  201. }
  202. }
  203. if (is_print_verbose_enabled()) {
  204. print_line(vformat("Generated '%s' preview in %d usec", p_item.path, OS::get_singleton()->get_ticks_usec() - started_at));
  205. }
  206. }
  207. const Dictionary EditorResourcePreview::get_preview_metadata(const String &p_path) const {
  208. ERR_FAIL_COND_V(!cache.has(p_path), Dictionary());
  209. return cache[p_path].preview_metadata;
  210. }
  211. void EditorResourcePreview::_iterate() {
  212. preview_mutex.lock();
  213. if (queue.size() == 0) {
  214. preview_mutex.unlock();
  215. return;
  216. }
  217. QueueItem item = queue.front()->get();
  218. queue.pop_front();
  219. if (cache.has(item.path)) {
  220. Item cached_item = cache[item.path];
  221. // Already has it because someone loaded it, just let it know it's ready.
  222. _preview_ready(item.path, cached_item.last_hash, cached_item.preview, cached_item.small_preview, item.id, item.function, item.userdata, cached_item.preview_metadata);
  223. preview_mutex.unlock();
  224. return;
  225. }
  226. preview_mutex.unlock();
  227. Ref<ImageTexture> texture;
  228. Ref<ImageTexture> small_texture;
  229. int thumbnail_size = EDITOR_GET("filesystem/file_dialog/thumbnail_size");
  230. thumbnail_size *= EDSCALE;
  231. if (item.resource.is_valid()) {
  232. Dictionary preview_metadata;
  233. _generate_preview(texture, small_texture, item, String(), preview_metadata);
  234. _preview_ready(item.path, item.resource->hash_edited_version_for_preview(), texture, small_texture, item.id, item.function, item.userdata, preview_metadata);
  235. return;
  236. }
  237. Dictionary preview_metadata;
  238. String temp_path = EditorPaths::get_singleton()->get_cache_dir();
  239. String cache_base = ProjectSettings::get_singleton()->globalize_path(item.path).md5_text();
  240. cache_base = temp_path.path_join("resthumb-" + cache_base);
  241. // Does not have it, try to load a cached thumbnail.
  242. String file = cache_base + ".txt";
  243. Ref<FileAccess> f = FileAccess::open(file, FileAccess::READ);
  244. if (f.is_null()) {
  245. // No cache found, generate.
  246. _generate_preview(texture, small_texture, item, cache_base, preview_metadata);
  247. } else {
  248. uint64_t modtime = FileAccess::get_modified_time(item.path);
  249. int tsize;
  250. bool has_small_texture;
  251. uint64_t last_modtime;
  252. String hash;
  253. bool outdated;
  254. _read_preview_cache(f, &tsize, &has_small_texture, &last_modtime, &hash, &preview_metadata, &outdated);
  255. bool cache_valid = true;
  256. if (tsize != thumbnail_size) {
  257. cache_valid = false;
  258. f.unref();
  259. } else if (outdated) {
  260. cache_valid = false;
  261. f.unref();
  262. } else if (last_modtime != modtime) {
  263. String last_md5 = f->get_line();
  264. String md5 = FileAccess::get_md5(item.path);
  265. f.unref();
  266. if (last_md5 != md5) {
  267. cache_valid = false;
  268. } else {
  269. // Update modified time.
  270. Ref<FileAccess> f2 = FileAccess::open(file, FileAccess::WRITE);
  271. if (f2.is_null()) {
  272. // Not returning as this would leave the thread hanging and would require
  273. // some proper cleanup/disabling of resource preview generation.
  274. ERR_PRINT("Cannot create file '" + file + "'. Check user write permissions.");
  275. } else {
  276. _write_preview_cache(f2, thumbnail_size, has_small_texture, modtime, md5, preview_metadata);
  277. }
  278. }
  279. } else {
  280. f.unref();
  281. }
  282. if (cache_valid) {
  283. Ref<Image> img;
  284. img.instantiate();
  285. Ref<Image> small_img;
  286. small_img.instantiate();
  287. if (img->load(cache_base + ".png") != OK) {
  288. cache_valid = false;
  289. } else {
  290. texture.instantiate();
  291. texture->set_image(img);
  292. if (has_small_texture) {
  293. if (small_img->load(cache_base + "_small.png") != OK) {
  294. cache_valid = false;
  295. } else {
  296. small_texture.instantiate();
  297. small_texture->set_image(small_img);
  298. }
  299. }
  300. }
  301. }
  302. if (!cache_valid) {
  303. _generate_preview(texture, small_texture, item, cache_base, preview_metadata);
  304. }
  305. }
  306. _preview_ready(item.path, 0, texture, small_texture, item.id, item.function, item.userdata, preview_metadata);
  307. }
  308. void EditorResourcePreview::_write_preview_cache(Ref<FileAccess> p_file, int p_thumbnail_size, bool p_has_small_texture, uint64_t p_modified_time, const String &p_hash, const Dictionary &p_metadata) {
  309. p_file->store_line(itos(p_thumbnail_size));
  310. p_file->store_line(itos(p_has_small_texture));
  311. p_file->store_line(itos(p_modified_time));
  312. p_file->store_line(p_hash);
  313. p_file->store_line(VariantUtilityFunctions::var_to_str(p_metadata).replace("\n", " "));
  314. p_file->store_line(itos(CURRENT_METADATA_VERSION));
  315. }
  316. void EditorResourcePreview::_read_preview_cache(Ref<FileAccess> p_file, int *r_thumbnail_size, bool *r_has_small_texture, uint64_t *r_modified_time, String *r_hash, Dictionary *r_metadata, bool *r_outdated) {
  317. *r_thumbnail_size = p_file->get_line().to_int();
  318. *r_has_small_texture = p_file->get_line().to_int();
  319. *r_modified_time = p_file->get_line().to_int();
  320. *r_hash = p_file->get_line();
  321. *r_metadata = VariantUtilityFunctions::str_to_var(p_file->get_line());
  322. *r_outdated = p_file->get_line().to_int() < CURRENT_METADATA_VERSION;
  323. }
  324. void EditorResourcePreview::_thread() {
  325. exited.clear();
  326. while (!exiting.is_set()) {
  327. preview_sem.wait();
  328. _iterate();
  329. }
  330. exited.set();
  331. }
  332. void EditorResourcePreview::_idle_callback() {
  333. if (!singleton) {
  334. // Just in case the shutdown of the editor involves the deletion of the singleton
  335. // happening while additional idle callbacks can happen.
  336. return;
  337. }
  338. // Process preview tasks, trying to leave a little bit of responsiveness worst case.
  339. uint64_t start = OS::get_singleton()->get_ticks_msec();
  340. while (!singleton->queue.is_empty() && OS::get_singleton()->get_ticks_msec() - start < 100) {
  341. singleton->_iterate();
  342. }
  343. }
  344. void EditorResourcePreview::_update_thumbnail_sizes() {
  345. if (small_thumbnail_size == -1) {
  346. // Kind of a workaround to retrieve the default icon size.
  347. small_thumbnail_size = EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Object"), EditorStringName(EditorIcons))->get_width();
  348. }
  349. }
  350. void EditorResourcePreview::queue_edited_resource_preview(const Ref<Resource> &p_res, Object *p_receiver, const StringName &p_receiver_func, const Variant &p_userdata) {
  351. ERR_FAIL_NULL(p_receiver);
  352. ERR_FAIL_COND(!p_res.is_valid());
  353. _update_thumbnail_sizes();
  354. {
  355. MutexLock lock(preview_mutex);
  356. String path_id = "ID:" + itos(p_res->get_instance_id());
  357. if (cache.has(path_id) && cache[path_id].last_hash == p_res->hash_edited_version_for_preview()) {
  358. p_receiver->call(p_receiver_func, path_id, cache[path_id].preview, cache[path_id].small_preview, p_userdata);
  359. return;
  360. }
  361. cache.erase(path_id); //erase if exists, since it will be regen
  362. QueueItem item;
  363. item.function = p_receiver_func;
  364. item.id = p_receiver->get_instance_id();
  365. item.resource = p_res;
  366. item.path = path_id;
  367. item.userdata = p_userdata;
  368. queue.push_back(item);
  369. }
  370. preview_sem.post();
  371. }
  372. void EditorResourcePreview::queue_resource_preview(const String &p_path, Object *p_receiver, const StringName &p_receiver_func, const Variant &p_userdata) {
  373. ERR_FAIL_NULL(p_receiver);
  374. _update_thumbnail_sizes();
  375. {
  376. MutexLock lock(preview_mutex);
  377. if (cache.has(p_path)) {
  378. p_receiver->call(p_receiver_func, p_path, cache[p_path].preview, cache[p_path].small_preview, p_userdata);
  379. return;
  380. }
  381. QueueItem item;
  382. item.function = p_receiver_func;
  383. item.id = p_receiver->get_instance_id();
  384. item.path = p_path;
  385. item.userdata = p_userdata;
  386. queue.push_back(item);
  387. }
  388. preview_sem.post();
  389. }
  390. void EditorResourcePreview::add_preview_generator(const Ref<EditorResourcePreviewGenerator> &p_generator) {
  391. preview_generators.push_back(p_generator);
  392. }
  393. void EditorResourcePreview::remove_preview_generator(const Ref<EditorResourcePreviewGenerator> &p_generator) {
  394. preview_generators.erase(p_generator);
  395. }
  396. EditorResourcePreview *EditorResourcePreview::get_singleton() {
  397. return singleton;
  398. }
  399. void EditorResourcePreview::_bind_methods() {
  400. ClassDB::bind_method(D_METHOD("queue_resource_preview", "path", "receiver", "receiver_func", "userdata"), &EditorResourcePreview::queue_resource_preview);
  401. ClassDB::bind_method(D_METHOD("queue_edited_resource_preview", "resource", "receiver", "receiver_func", "userdata"), &EditorResourcePreview::queue_edited_resource_preview);
  402. ClassDB::bind_method(D_METHOD("add_preview_generator", "generator"), &EditorResourcePreview::add_preview_generator);
  403. ClassDB::bind_method(D_METHOD("remove_preview_generator", "generator"), &EditorResourcePreview::remove_preview_generator);
  404. ClassDB::bind_method(D_METHOD("check_for_invalidation", "path"), &EditorResourcePreview::check_for_invalidation);
  405. ADD_SIGNAL(MethodInfo("preview_invalidated", PropertyInfo(Variant::STRING, "path")));
  406. }
  407. void EditorResourcePreview::check_for_invalidation(const String &p_path) {
  408. bool call_invalidated = false;
  409. {
  410. MutexLock lock(preview_mutex);
  411. if (cache.has(p_path)) {
  412. uint64_t modified_time = FileAccess::get_modified_time(p_path);
  413. if (modified_time != cache[p_path].modified_time) {
  414. cache.erase(p_path);
  415. call_invalidated = true;
  416. }
  417. }
  418. }
  419. if (call_invalidated) { //do outside mutex
  420. call_deferred(SNAME("emit_signal"), "preview_invalidated", p_path);
  421. }
  422. }
  423. void EditorResourcePreview::start() {
  424. if (DisplayServer::get_singleton()->get_name() == "headless") {
  425. return;
  426. }
  427. if (is_threaded()) {
  428. ERR_FAIL_COND_MSG(thread.is_started(), "Thread already started.");
  429. thread.start(_thread_func, this);
  430. } else {
  431. SceneTree *st = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
  432. ERR_FAIL_NULL_MSG(st, "Editor's MainLoop is not a SceneTree. This is a bug.");
  433. st->add_idle_callback(&_idle_callback);
  434. }
  435. }
  436. void EditorResourcePreview::stop() {
  437. if (is_threaded()) {
  438. if (thread.is_started()) {
  439. exiting.set();
  440. preview_sem.post();
  441. for (int i = 0; i < preview_generators.size(); i++) {
  442. preview_generators.write[i]->abort();
  443. }
  444. while (!exited.is_set()) {
  445. OS::get_singleton()->delay_usec(10000);
  446. RenderingServer::get_singleton()->sync(); //sync pending stuff, as thread may be blocked on rendering server
  447. }
  448. thread.wait_to_finish();
  449. }
  450. }
  451. }
  452. EditorResourcePreview::EditorResourcePreview() {
  453. singleton = this;
  454. }
  455. EditorResourcePreview::~EditorResourcePreview() {
  456. stop();
  457. }