BMain: Add utils to check if a Main is empty or not.

Mostly intended for debug code (asserts).
This commit is contained in:
Bastien Montagne 2021-10-06 16:41:08 +02:00
parent 0194e54fd3
commit b7dc0346aa
2 changed files with 13 additions and 0 deletions

View File

@ -201,6 +201,8 @@ typedef struct Main {
struct Main *BKE_main_new(void);
void BKE_main_free(struct Main *mainvar);
bool BKE_main_is_empty(struct Main *bmain);
void BKE_main_lock(struct Main *bmain);
void BKE_main_unlock(struct Main *bmain);

View File

@ -205,6 +205,17 @@ void BKE_main_free(Main *mainvar)
MEM_freeN(mainvar);
}
/* Check whether given `bmain` is empty or contains some IDs. */
bool BKE_main_is_empty(struct Main *bmain)
{
ID *id_iter;
FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
return false;
}
FOREACH_MAIN_ID_END;
return true;
}
void BKE_main_lock(struct Main *bmain)
{
BLI_spin_lock((SpinLock *)bmain->lock);