Fix writefile making all linked IDs directly linked.

Regression from 435b6743fd, when considering UI ID usages to define
if IDs are weekly direclty linked, cases where this should not be the
case (e.g. Outliber ID pointers) ended up making them directly linked.

So essentially, all linked data became directly linked when writing the
blendfile on disk!

Fixed by adding a new `IDWALK_CB_WRITEFILE_IGNORE`, to tell the
writefile code that it can ignore this ID usage (similar to the existing
`IDWALK_CB_READFILE_IGNORE` one).

Pull Request: https://projects.blender.org/blender/blender/pulls/146667
This commit is contained in:
Bastien Montagne
2025-09-24 11:55:53 +02:00
committed by Bastien Montagne
parent 00612f0960
commit 0224d3083b
3 changed files with 22 additions and 9 deletions

View File

@@ -90,18 +90,25 @@ enum LibraryForeachIDCallbackFlag {
* Mainly used for some 'loop-back' pointers like the 'owner_id' of the embedded IDs.
*/
IDWALK_CB_READFILE_IGNORE = (1 << 10),
/**
* This ID usage should not be processed during writefile.
*
* Mainly used to avoid explicit reference to some linked data from UI, like e.g. the Outliner
* making all IDs 'directly linked'..
*/
IDWALK_CB_WRITEFILE_IGNORE = (1 << 11),
/**
* This ID usage is fully refcounted.
* Callback is responsible to deal accordingly with #ID.us if needed.
*/
IDWALK_CB_USER = (1 << 11),
IDWALK_CB_USER = (1 << 12),
/**
* This ID usage is not refcounted, but at least one user should be generated by it (to avoid
* e.g. losing the used ID on save/reload).
* Callback is responsible to deal accordingly with #ID.us if needed.
*/
IDWALK_CB_USER_ONE = (1 << 12),
IDWALK_CB_USER_ONE = (1 << 13),
/** This ID is used as library override's reference by its owner. */
IDWALK_CB_OVERRIDE_LIBRARY_REFERENCE = (1 << 16),

View File

@@ -1375,6 +1375,12 @@ static int write_id_direct_linked_data_process_cb(LibraryIDLinkCallbackData *cb_
return IDWALK_RET_NOP;
}
if (cb_flag & IDWALK_CB_WRITEFILE_IGNORE) {
/* Do not consider these ID usages (typically, from the Outliner e.g.) as making the ID
* directly linked. */
return IDWALK_RET_NOP;
}
if (!BKE_idtype_idcode_is_linkable(GS(id->name))) {
/* Usages of unlinkable IDs (aka ShapeKeys and some UI IDs) should never cause them to be
* considered as directly linked. This can often happen e.g. from UI data (the Outliner will

View File

@@ -514,13 +514,13 @@ static void outliner_foreach_id(SpaceLink *space_link, LibraryForeachIDData *dat
/* Do not try to restore non-ID pointers (drivers/sequence/etc.). */
if (TSE_IS_REAL_ID(tselem)) {
/* NOTE: Outliner ID pointers are never `IDWALK_CB_DIRECT_WEAK_LINK`, they should never
* enforce keeping a reference to some linked data. */
const LibraryForeachIDCallbackFlag cb_flag = (tselem->id != nullptr &&
allow_pointer_access &&
(tselem->id->flag & ID_FLAG_EMBEDDED_DATA) !=
0) ?
IDWALK_CB_EMBEDDED_NOT_OWNING :
IDWALK_CB_NOP;
* enforce keeping a reference to some linked data. They do need to be explicitely ignored by
* writefile code though. */
const LibraryForeachIDCallbackFlag cb_flag =
IDWALK_CB_WRITEFILE_IGNORE | ((tselem->id != nullptr && allow_pointer_access &&
(tselem->id->flag & ID_FLAG_EMBEDDED_DATA) != 0) ?
IDWALK_CB_EMBEDDED_NOT_OWNING :
IDWALK_CB_NOP);
BKE_LIB_FOREACHID_PROCESS_ID(data, tselem->id, cb_flag);
}
else if (!is_readonly) {