From 4137cc79f25333534faa08a34ec3bc2a0ee4dc61 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 29 Jun 2016 22:09:37 +0200 Subject: Cleanup: rename BKE_asset to BKE_asset_engine. Since this file mostly defines/handles interactions with asset engines... Asset handling itself is more done in library area (will split it too in next commit). --- source/blender/windowmanager/intern/wm_event_system.c | 2 +- source/blender/windowmanager/intern/wm_files_link.c | 2 +- source/blender/windowmanager/intern/wm_init_exit.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source/blender/windowmanager') diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 4a48143b87b..51fbabac638 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -52,7 +52,7 @@ #include "RNA_access.h" -#include "BKE_asset.h" +#include "BKE_asset_engine.h" #include "BKE_context.h" #include "BKE_idprop.h" #include "BKE_global.h" diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c index f3792e0bac6..b06fc696ac9 100644 --- a/source/blender/windowmanager/intern/wm_files_link.c +++ b/source/blender/windowmanager/intern/wm_files_link.c @@ -62,7 +62,7 @@ #include "BLO_readfile.h" -#include "BKE_asset.h" +#include "BKE_asset_engine.h" #include "BKE_context.h" #include "BKE_depsgraph.h" #include "BKE_library.h" diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 4d5156f9ae5..91322c857ab 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -56,7 +56,7 @@ #include "BLO_writefile.h" -#include "BKE_asset.h" +#include "BKE_asset_engine.h" #include "BKE_blender.h" #include "BKE_blender_undo.h" #include "BKE_context.h" -- cgit v1.2.3 From 3db91def28be4480e60b46720ae7f307fcab7c7d Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 30 Jun 2016 10:41:03 +0200 Subject: Reduce re-allocation while fetching UUIDs per asset engine (asset reload area). --- source/blender/windowmanager/intern/wm_files_link.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'source/blender/windowmanager') diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c index b06fc696ac9..7b5097511c5 100644 --- a/source/blender/windowmanager/intern/wm_files_link.c +++ b/source/blender/windowmanager/intern/wm_files_link.c @@ -1066,9 +1066,10 @@ typedef struct AssetUpdateCheckEngine { AssetEngine *ae; /* Note: We cannot store IDs themselves in non-locking async task... so we'll have to check again for - * UUID/IDs mapping on each update call... Not ideal, but don't think it will be that big of an override + * UUID/IDs mapping on each update call... Not ideal, but don't think it will be that big of a bottleneck * in practice. */ AssetUUIDList uuids; + int allocated_uuids; int ae_job_id; short status; } AssetUpdateCheckEngine; @@ -1170,13 +1171,16 @@ static void asset_update_engines_uuids_fetch( id->uuid->tag = (id->tag & LIB_TAG_MISSING) ? UUID_TAG_ASSET_MISSING : 0; } - /* XXX horrible, need to use some mempool, stack or something :) */ auce->uuids.nbr_uuids++; - if (auce->uuids.uuids) { - auce->uuids.uuids = MEM_reallocN_id(auce->uuids.uuids, sizeof(*auce->uuids.uuids) * (size_t)auce->uuids.nbr_uuids, __func__); - } - else { - auce->uuids.uuids = MEM_mallocN(sizeof(*auce->uuids.uuids) * (size_t)auce->uuids.nbr_uuids, __func__); + BKE_asset_uuid_print(id->uuid); + if (auce->uuids.nbr_uuids > auce->allocated_uuids) { + auce->allocated_uuids += 16; + BLI_assert(auce->uuids.nbr_uuids < auce->allocated_uuids); + + const size_t allocsize = sizeof(*auce->uuids.uuids) * (size_t)auce->allocated_uuids; + auce->uuids.uuids = auce->uuids.uuids ? + MEM_reallocN_id(auce->uuids.uuids, allocsize, __func__) : + MEM_mallocN(allocsize, __func__); } auce->uuids.uuids[auce->uuids.nbr_uuids - 1] = *id->uuid; } -- cgit v1.2.3 From 3bfa8d9fd47936ad46e7030af7e4e0d9d4f1c35c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 15 Jul 2016 15:29:27 +1000 Subject: Fix py-driver in startup.blend crash in background mode Obscure regression in own commit from b34929786. While this could be considered correct, it introduces a crash so disable the update call. --- source/blender/windowmanager/intern/wm_files.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source/blender/windowmanager') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 729af731dfe..fe257cc4c41 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -482,8 +482,6 @@ static void wm_file_read_post(bContext *C, bool is_startup_file) BPY_python_reset(C); addons_loaded = true; } -#else - UNUSED_VARS(is_startup_file); #endif /* WITH_PYTHON */ WM_operatortype_last_properties_clear_all(); @@ -492,8 +490,12 @@ static void wm_file_read_post(bContext *C, bool is_startup_file) BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_VERSION_UPDATE); BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_POST); - /* would otherwise be handled by event loop */ - if (G.background) { + /* Would otherwise be handled by event loop. + * + * Disabled for startup file, since it causes problems when PyDrivers are used in the startup file. + * While its possible state of startup file may be wrong, + * in this case users nearly always load a file to replace the startup file. */ + if (G.background && (is_startup_file == false)) { Main *bmain = CTX_data_main(C); BKE_scene_update_tagged(bmain->eval_ctx, bmain, CTX_data_scene(C)); } -- cgit v1.2.3 From 5f4a3785c6bdf7b329d9230369b77bc0da0bc297 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 19 Jul 2016 17:49:01 +0200 Subject: Add 'reload' function to libraries' RNA API. --- source/blender/windowmanager/WM_api.h | 2 + .../blender/windowmanager/intern/wm_files_link.c | 115 ++++++++++++--------- 2 files changed, 71 insertions(+), 46 deletions(-) (limited to 'source/blender/windowmanager') diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 7a247d9791b..26a1c7038d8 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -114,6 +114,8 @@ void WM_autosave_init(struct wmWindowManager *wm); void WM_recover_last_session(struct bContext *C, struct ReportList *reports); void WM_file_tag_modified(const struct bContext *C); +void WM_lib_reload(struct Library *lib, struct bContext *C, struct ReportList *reports); + /* mouse cursors */ void WM_cursor_set(struct wmWindow *win, int curs); void WM_cursor_modal_set(struct wmWindow *win, int curs); diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c index 12ad8f91064..e2ccb6fbbd7 100644 --- a/source/blender/windowmanager/intern/wm_files_link.c +++ b/source/blender/windowmanager/intern/wm_files_link.c @@ -551,8 +551,9 @@ static int wm_lib_relocate_invoke(bContext *C, wmOperator *op, const wmEvent *UN return OPERATOR_CANCELLED; } -/* Note that IDs listed in lapp_data items *must* have been removed from bmain by caller. */ -static void lib_relocate_do(Main *bmain, WMLinkAppendData *lapp_data, ReportList *reports, const bool do_reload) +static void lib_relocate_do( + Main *bmain, Scene *scene, + Library *library, WMLinkAppendData *lapp_data, ReportList *reports, const bool do_reload) { ListBase *lbarray[MAX_LIBARRAY]; int lba_idx; @@ -560,6 +561,34 @@ static void lib_relocate_do(Main *bmain, WMLinkAppendData *lapp_data, ReportList LinkNode *itemlink; int item_idx; + /* Remove all IDs to be reloaded from Main. */ + lba_idx = set_listbasepointers(bmain, lbarray); + while (lba_idx--) { + ID *id = lbarray[lba_idx]->first; + const short idcode = id ? GS(id->name) : 0; + + if (!id || !BKE_idcode_is_linkable(idcode)) { + /* No need to reload non-linkable datatypes, those will get relinked with their 'users ID'. */ + continue; + } + + for (; id; id = id->next) { + if (id->lib == library) { + WMLinkAppendDataItem *item; + + /* We remove it from current Main, and add it to items to link... */ + /* Note that non-linkable IDs (like e.g. shapekeys) are also explicitely linked here... */ + BLI_remlink(lbarray[lba_idx], id); + item = wm_link_append_data_item_add(lapp_data, id->name + 2, idcode, id); + BLI_BITMAP_SET_ALL(item->libraries, true, lapp_data->num_libraries); + +#ifdef PRINT_DEBUG + printf("\tdatablock to seek for: %s\n", id->name); +#endif + } + } + } + BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true); /* We do not want any instanciation here! */ @@ -698,6 +727,43 @@ static void lib_relocate_do(Main *bmain, WMLinkAppendData *lapp_data, ReportList } } } + + BKE_main_lib_objects_recalc_all(bmain); + IMB_colormanagement_check_file_config(bmain); + + /* important we unset, otherwise these object wont + * link into other scenes from this blend file */ + BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false); + + /* recreate dependency graph to include new objects */ + DAG_scene_relations_rebuild(bmain, scene); + + /* free gpu materials, some materials depend on existing objects, such as lamps so freeing correctly refreshes */ + GPU_materials_free(); +} + +void WM_lib_reload(Library *lib, bContext *C, ReportList *reports) +{ + if (!BLO_has_bfile_extension(lib->filepath)) { + BKE_reportf(reports, RPT_ERROR, "'%s' is not a valid library filepath", lib->filepath); + return; + } + + if (!BLI_exists(lib->filepath)) { + BKE_reportf(reports, RPT_ERROR, + "Trying to reload library '%s' from invalid path '%s'", lib->id.name, lib->filepath); + return; + } + + WMLinkAppendData *lapp_data = wm_link_append_data_new(0); + + wm_link_append_data_library_add(lapp_data, lib->filepath); + + lib_relocate_do(CTX_data_main(C), CTX_data_scene(C), lib, lapp_data, reports, true); + + wm_link_append_data_free(lapp_data); + + WM_event_add_notifier(C, NC_WINDOW, NULL); } static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload) @@ -714,9 +780,6 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload) PropertyRNA *prop; WMLinkAppendData *lapp_data; - ListBase *lbarray[MAX_LIBARRAY]; - int lba_idx; - char path[FILE_MAX], root[FILE_MAXDIR], libname[FILE_MAX], relname[FILE_MAX]; short flag = 0; @@ -803,50 +866,10 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload) } } - lba_idx = set_listbasepointers(bmain, lbarray); - while (lba_idx--) { - ID *id = lbarray[lba_idx]->first; - const short idcode = id ? GS(id->name) : 0; - - if (!id || !BKE_idcode_is_linkable(idcode)) { - /* No need to reload non-linkable datatypes, those will get relinked with their 'users ID'. */ - continue; - } - - for (; id; id = id->next) { - if (id->lib == lib) { - WMLinkAppendDataItem *item; - - /* We remove it from current Main, and add it to items to link... */ - /* Note that non-linkable IDs (like e.g. shapekeys) are also explicitely linked here... */ - BLI_remlink(lbarray[lba_idx], id); - item = wm_link_append_data_item_add(lapp_data, id->name + 2, idcode, id); - BLI_BITMAP_SET_ALL(item->libraries, true, lapp_data->num_libraries); - -#ifdef PRINT_DEBUG - printf("\tdatablock to seek for: %s\n", id->name); -#endif - } - } - } - - lib_relocate_do(bmain, lapp_data, op->reports, do_reload); + lib_relocate_do(bmain, scene, lib, lapp_data, op->reports, do_reload); wm_link_append_data_free(lapp_data); - BKE_main_lib_objects_recalc_all(bmain); - IMB_colormanagement_check_file_config(bmain); - - /* important we unset, otherwise these object wont - * link into other scenes from this blend file */ - BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false); - - /* recreate dependency graph to include new objects */ - DAG_scene_relations_rebuild(bmain, scene); - - /* free gpu materials, some materials depend on existing objects, such as lamps so freeing correctly refreshes */ - GPU_materials_free(); - /* XXX TODO: align G.lib with other directory storage (like last opened image etc...) */ BLI_strncpy(G.lib, root, FILE_MAX); -- cgit v1.2.3