From b47a234f98dd7e6e0b53ad96b5b4d278635874d8 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 5 Oct 2022 12:55:32 +0200 Subject: BKE_Main: Add clear separation between 'temp' mains and global main. Blender is using more and more temporary Main data-base (historically for reading linked data, but also now when resyncing liboverrides, for temp data in asset code, etc.). This commit aims at making this a bit more formal and defined, by: * Adding a dedicated flag in Main struct to mark a Main as global. * Adding some API to replace, or temporarily swap the current global Main (`G_MAIN`) by another one. NOTE: Having to temporarily replace `G_MAIN` is a workaround for the limitation of current RNA, ideally this should be fixed in RNA itself, but for now at least having an API helps tracking those cases (since this is potentially risky operation). This work is also a preparation for more usages of temp mains in the near future (Asset Brushes and its presets system e.g. will most likely use temp mains too). Reviewed By: brecht Differential Revision: https://developer.blender.org/D15977 --- source/blender/blenloader/intern/versioning_280.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index 3e26516cd69..a9048037513 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -53,6 +53,7 @@ #include "DNA_world_types.h" #include "BKE_animsys.h" +#include "BKE_blender.h" #include "BKE_brush.h" #include "BKE_cloth.h" #include "BKE_collection.h" @@ -1613,12 +1614,13 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports)) if (me->totface && !me->totpoly) { /* temporarily switch main so that reading from * external CustomData works */ - Main *gmain = G_MAIN; - G_MAIN = bmain; + Main *orig_gmain = BKE_blender_globals_main_swap(bmain); BKE_mesh_do_versions_convert_mfaces_to_mpolys(me); - G_MAIN = gmain; + Main *tmp_gmain = BKE_blender_globals_main_swap(orig_gmain); + BLI_assert(tmp_gmain == bmain); + UNUSED_VARS_NDEBUG(tmp_gmain); } /* Deprecated, only kept for conversion. */ -- cgit v1.2.3