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:
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user