From 58bd3d40ee20d105bbcbe09f8d1ebf3d4075b1dc Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Fri, 23 Aug 2024 19:49:10 +0200 Subject: [PATCH] Fix #124752: Push an undo step when USD background import completes This was a very similar problem to Alembic's #77754 where a background import can cause issues with Undo in some circumstances. Mirror what was done for the Alembic fix here now too. Pull Request: https://projects.blender.org/blender/blender/pulls/126539 --- source/blender/io/usd/intern/usd_capi_import.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index e409e58da2a..5d504ed3e46 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -40,6 +40,8 @@ #include "DNA_scene_types.h" #include "DNA_windowmanager_types.h" +#include "ED_undo.hh" + #include "MEM_guardedalloc.h" #include "WM_api.hh" @@ -156,6 +158,7 @@ enum { }; struct ImportJobData { + bContext *C; Main *bmain; Scene *scene; ViewLayer *view_layer; @@ -174,6 +177,7 @@ struct ImportJobData { char error_code; bool was_canceled; bool import_ok; + bool is_background_job; timeit::TimePoint start_time; CacheFile *cache_file; @@ -455,6 +459,12 @@ static void import_endjob(void *customdata) register_hook_converters(); call_import_hooks(data->archive->stage(), data->params.worker_status->reports); + + if (data->is_background_job) { + /* Blender already returned from the import operator, so we need to store our own extra undo + * step. */ + ED_undo_push(data->C, "USD Import Finished"); + } } WM_set_locked_interface(data->wm, false); @@ -493,11 +503,13 @@ bool USD_import(const bContext *C, { /* Using new here since `MEM_*` functions do not call constructor to properly initialize data. */ ImportJobData *job = new ImportJobData(); + job->C = const_cast(C); job->bmain = CTX_data_main(C); job->scene = CTX_data_scene(C); job->view_layer = CTX_data_view_layer(C); job->wm = CTX_wm_manager(C); job->import_ok = false; + job->is_background_job = as_background_job; STRNCPY(job->filepath, filepath); job->settings.scale = params->scale;