Core: Cleanup: foreach_id: document acceptable return values from callbacks.

Essentially, callbacks in non-readonly are never expected to early-abort
the ID usages iteration. Add comments and an assert to ensure this.
This commit is contained in:
Bastien Montagne
2024-06-26 19:11:10 +02:00
parent 1d7dc7190f
commit a50ab48709
2 changed files with 17 additions and 2 deletions

View File

@@ -117,9 +117,17 @@ enum {
enum {
IDWALK_RET_NOP = 0,
/** Completely stop iteration. */
/**
* Completely stop iteration.
*
* \note Should never be returned by a callback in case #IDWALK_READONLY is not set.
*/
IDWALK_RET_STOP_ITER = 1 << 0,
/** Stop recursion, that is, do not loop over ID used by current one. */
/**
* Stop recursion, that is, do not loop over ID used by current one.
*
* \note Should never be returned by a callback in case #IDWALK_READONLY is not set.
*/
IDWALK_RET_STOP_RECURSION = 1 << 1,
};

View File

@@ -95,9 +95,16 @@ void BKE_lib_query_foreachid_process(LibraryForeachIDData *data, ID **id_pp, int
callback_data.id_pointer = id_pp;
callback_data.cb_flag = cb_flag;
const int callback_return = data->callback(&callback_data);
if (flag & IDWALK_READONLY) {
BLI_assert(*(id_pp) == old_id);
}
else {
BLI_assert_msg((callback_return & (IDWALK_RET_STOP_ITER | IDWALK_RET_STOP_RECURSION)) == 0,
"Iteration over ID usages should not be interrupted by the callback in "
"non-readonly cases");
}
if (old_id && (flag & IDWALK_RECURSE)) {
if (BLI_gset_add((data)->ids_handled, old_id)) {
if (!(callback_return & IDWALK_RET_STOP_RECURSION)) {