Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/library.c
| Show All 33 Lines | |||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <ctype.h> | #include <ctype.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include <stddef.h> | #include <stddef.h> | ||||
| #include <assert.h> | #include <assert.h> | ||||
| #include "CLG_log.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| /* all types are needed here, in order to do memory operations */ | /* all types are needed here, in order to do memory operations */ | ||||
| #include "DNA_anim_types.h" | #include "DNA_anim_types.h" | ||||
| #include "DNA_armature_types.h" | #include "DNA_armature_types.h" | ||||
| #include "DNA_brush_types.h" | #include "DNA_brush_types.h" | ||||
| #include "DNA_cachefile_types.h" | #include "DNA_cachefile_types.h" | ||||
| #include "DNA_camera_types.h" | #include "DNA_camera_types.h" | ||||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | |||||
| #include "atomic_ops.h" | #include "atomic_ops.h" | ||||
| //#define DEBUG_TIME | //#define DEBUG_TIME | ||||
| #ifdef DEBUG_TIME | #ifdef DEBUG_TIME | ||||
| # include "PIL_time_utildefines.h" | # include "PIL_time_utildefines.h" | ||||
| #endif | #endif | ||||
| static CLG_LogRef LOG = {"bke.library"}; | |||||
| /* GS reads the memory pointed at in a specific ordering. | /* GS reads the memory pointed at in a specific ordering. | ||||
| * only use this definition, makes little and big endian systems | * only use this definition, makes little and big endian systems | ||||
| * work fine, in conjunction with MAKE_ID */ | * work fine, in conjunction with MAKE_ID */ | ||||
| /* ************* general ************************ */ | /* ************* general ************************ */ | ||||
| /* this has to be called from each make_local_* func, we could call | /* this has to be called from each make_local_* func, we could call | ||||
| Show All 28 Lines | |||||
| * to make this change... */ | * to make this change... */ | ||||
| void id_us_ensure_real(ID *id) | void id_us_ensure_real(ID *id) | ||||
| { | { | ||||
| if (id) { | if (id) { | ||||
| const int limit = ID_FAKE_USERS(id); | const int limit = ID_FAKE_USERS(id); | ||||
| id->tag |= LIB_TAG_EXTRAUSER; | id->tag |= LIB_TAG_EXTRAUSER; | ||||
| if (id->us <= limit) { | if (id->us <= limit) { | ||||
| if (id->us < limit || ((id->us == limit) && (id->tag & LIB_TAG_EXTRAUSER_SET))) { | if (id->us < limit || ((id->us == limit) && (id->tag & LIB_TAG_EXTRAUSER_SET))) { | ||||
| printf("ID user count error: %s (from '%s')\n", id->name, id->lib ? id->lib->filepath : "[Main]"); | CLOG_FATAL(&LOG, "ID user count error: %s (from '%s')", id->name, id->lib ? id->lib->filepath : "[Main]"); | ||||
| BLI_assert(0); | BLI_assert(0); | ||||
| } | } | ||||
| id->us = limit + 1; | id->us = limit + 1; | ||||
| id->tag |= LIB_TAG_EXTRAUSER_SET; | id->tag |= LIB_TAG_EXTRAUSER_SET; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 39 Lines | |||||
| /* decrements the user count for *id. */ | /* decrements the user count for *id. */ | ||||
| void id_us_min(ID *id) | void id_us_min(ID *id) | ||||
| { | { | ||||
| if (id) { | if (id) { | ||||
| const int limit = ID_FAKE_USERS(id); | const int limit = ID_FAKE_USERS(id); | ||||
| if (id->us <= limit) { | if (id->us <= limit) { | ||||
| printf("ID user decrement error: %s (from '%s'): %d <= %d\n", | CLOG_FATAL(&LOG, "ID user decrement error: %s (from '%s'): %d <= %d", | ||||
| id->name, id->lib ? id->lib->filepath : "[Main]", id->us, limit); | id->name, id->lib ? id->lib->filepath : "[Main]", id->us, limit); | ||||
| BLI_assert(0); | BLI_assert(0); | ||||
| id->us = limit; | id->us = limit; | ||||
| } | } | ||||
| else { | else { | ||||
| id->us--; | id->us--; | ||||
| } | } | ||||
| if ((id->us == limit) && (id->tag & LIB_TAG_EXTRAUSER)) { | if ((id->us == limit) && (id->tag & LIB_TAG_EXTRAUSER)) { | ||||
| ▲ Show 20 Lines • Show All 1,687 Lines • ▼ Show 20 Lines | for (LinkNode *it = copied_ids; it; it = it->next) { | ||||
| * TL;DR: this is a dirty hack on top of an already weak feature (proxies). */ | * TL;DR: this is a dirty hack on top of an already weak feature (proxies). */ | ||||
| if (GS(id->name) == ID_OB && ((Object *)id)->proxy != NULL) { | if (GS(id->name) == ID_OB && ((Object *)id)->proxy != NULL) { | ||||
| Object *ob = (Object *)id; | Object *ob = (Object *)id; | ||||
| Object *ob_new = (Object *)id->newid; | Object *ob_new = (Object *)id->newid; | ||||
| bool is_local = false, is_lib = false; | bool is_local = false, is_lib = false; | ||||
| /* Proxies only work when the proxified object is linked-in from a library. */ | /* Proxies only work when the proxified object is linked-in from a library. */ | ||||
| if (ob->proxy->id.lib == NULL) { | if (ob->proxy->id.lib == NULL) { | ||||
| printf("Warning, proxy object %s will loose its link to %s, because the " | CLOG_WARN(&LOG, "proxy object %s will loose its link to %s, because the " | ||||
| "proxified object is local.\n", id->newid->name, ob->proxy->id.name); | "proxified object is local.", id->newid->name, ob->proxy->id.name); | ||||
| continue; | continue; | ||||
| } | } | ||||
| BKE_library_ID_test_usages(bmain, id, &is_local, &is_lib); | BKE_library_ID_test_usages(bmain, id, &is_local, &is_lib); | ||||
| /* We can only switch the proxy'ing to a made-local proxy if it is no longer | /* We can only switch the proxy'ing to a made-local proxy if it is no longer | ||||
| * referred to from a library. Not checking for local use; if new local proxy | * referred to from a library. Not checking for local use; if new local proxy | ||||
| * was not used locally would be a nasty bug! */ | * was not used locally would be a nasty bug! */ | ||||
| if (is_local || is_lib) { | if (is_local || is_lib) { | ||||
| printf("Warning, made-local proxy object %s will loose its link to %s, " | CLOG_WARN(&LOG, "made-local proxy object %s will loose its link to %s, " | ||||
| "because the linked-in proxy is referenced (is_local=%i, is_lib=%i).\n", | "because the linked-in proxy is referenced (is_local=%i, is_lib=%i).", | ||||
| id->newid->name, ob->proxy->id.name, is_local, is_lib); | id->newid->name, ob->proxy->id.name, is_local, is_lib); | ||||
| } | } | ||||
| else { | else { | ||||
| /* we can switch the proxy'ing from the linked-in to the made-local proxy. | /* we can switch the proxy'ing from the linked-in to the made-local proxy. | ||||
| * BKE_object_make_proxy() shouldn't be used here, as it allocates memory that | * BKE_object_make_proxy() shouldn't be used here, as it allocates memory that | ||||
| * was already allocated by BKE_object_make_local_ex() (which called BKE_object_copy_ex). */ | * was already allocated by BKE_object_make_local_ex() (which called BKE_object_copy_ex). */ | ||||
| ob_new->proxy = ob->proxy; | ob_new->proxy = ob->proxy; | ||||
| ob_new->proxy_group = ob->proxy_group; | ob_new->proxy_group = ob->proxy_group; | ||||
| ▲ Show 20 Lines • Show All 267 Lines • Show Last 20 Lines | |||||