Cleanup: ID usercount: moar checks and factorization. No change in behavior expected.
authorBastien Montagne <montagne29@wanadoo.fr>
Tue, 10 Nov 2015 15:20:28 +0000 (16:20 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Tue, 10 Nov 2015 15:21:09 +0000 (16:21 +0100)
source/blender/blenkernel/intern/library.c
source/blender/makesdna/DNA_ID.h

index b76323bef31d40a1c29ab05a95b6fef7eb2c7c7a..1dff424b6cccd4ef65507e147b3df4c7099257c9 100644 (file)
@@ -163,8 +163,13 @@ void id_lib_extern(ID *id)
 void id_us_ensure_real(ID *id)
 {
        if (id) {
-               if (ID_REAL_USERS(id) <= 0) {
-                       id->us = MAX2(id->us, 0) + 1;
+               const int limit = ID_FAKE_USERS(id);
+               if (id->us <= limit) {
+                       if (id->us < limit) {
+                               printf("ID user count error: %s (from '%s')\n", id->name, id->lib ? id->lib->filepath : "[Main]");
+                               BLI_assert(0);
+                       }
+                       id->us = limit + 1;
                }
        }
 }
@@ -172,6 +177,7 @@ void id_us_ensure_real(ID *id)
 void id_us_plus(ID *id)
 {
        if (id) {
+               BLI_assert(id->us >= 0);
                id->us++;
                if (id->flag & LIB_INDIRECT) {
                        id->flag -= LIB_INDIRECT;
@@ -184,7 +190,7 @@ void id_us_plus(ID *id)
 void id_us_min(ID *id)
 {
        if (id) {
-               const int limit = (id->flag & LIB_FAKEUSER) ? 1 : 0;
+               const int limit = ID_FAKE_USERS(id);
                if (id->us <= limit) {
                        printf("ID user decrement error: %s (from '%s')\n", id->name, id->lib ? id->lib->filepath : "[Main]");
                        BLI_assert(0);
index 9aff8d74e30a20bc177a0b443e2875a906affb19..1d140f9570d9e130e237e4355cf6de40d98711e5 100644 (file)
@@ -254,7 +254,8 @@ typedef struct PreviewImage {
                        /* fluidsim Ipo */
 #define ID_FLUIDSIM    MAKE_ID2('F', 'S')
 
-#define ID_REAL_USERS(id) (((ID *)id)->us - ((((ID *)id)->flag & LIB_FAKEUSER) ? 1 : 0))
+#define ID_FAKE_USERS(id) ((((ID *)id)->flag & LIB_FAKEUSER) ? 1 : 0)
+#define ID_REAL_USERS(id) (((ID *)id)->us - ID_FAKE_USERS(id))
 
 #define ID_CHECK_UNDO(id) ((GS((id)->name) != ID_SCR) && (GS((id)->name) != ID_WM))