Changeset View
Changeset View
Standalone View
Standalone View
source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
| Show First 20 Lines • Show All 816 Lines • ▼ Show 20 Lines | if (!deg_copy_on_write_is_needed(id_orig)) { | ||||
| return id_cow; | return id_cow; | ||||
| } | } | ||||
| DEG_COW_PRINT( | DEG_COW_PRINT( | ||||
| "Expanding datablock for %s: id_orig=%p id_cow=%p\n", id_orig->name, id_orig, id_cow); | "Expanding datablock for %s: id_orig=%p id_cow=%p\n", id_orig->name, id_orig, id_cow); | ||||
| /* Sanity checks. */ | /* Sanity checks. */ | ||||
| BLI_assert(check_datablock_expanded(id_cow) == false); | BLI_assert(check_datablock_expanded(id_cow) == false); | ||||
| BLI_assert(id_cow->py_instance == nullptr); | |||||
| /* Copy data from original ID to a copied version. */ | /* Copy data from original ID to a copied version. */ | ||||
| /* TODO(sergey): Avoid doing full ID copy somehow, make Mesh to reference | /* TODO(sergey): Avoid doing full ID copy somehow, make Mesh to reference | ||||
| * original geometry arrays for until those are modified. */ | * original geometry arrays for until those are modified. */ | ||||
| /* TODO(sergey): We do some trickery with temp bmain and extra ID pointer | /* TODO(sergey): We do some trickery with temp bmain and extra ID pointer | ||||
| * just to be able to use existing API. Ideally we need to replace this with | * just to be able to use existing API. Ideally we need to replace this with | ||||
| * in-place copy from existing datablock to a prepared memory. | * in-place copy from existing datablock to a prepared memory. | ||||
| * | * | ||||
| ▲ Show 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | case ID_OB: { | ||||
| Object *ob_cow = (Object *)id_cow; | Object *ob_cow = (Object *)id_cow; | ||||
| ob_cow->data = nullptr; | ob_cow->data = nullptr; | ||||
| ob_cow->sculpt = nullptr; | ob_cow->sculpt = nullptr; | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| discard_edit_mode_pointers(id_cow); | discard_edit_mode_pointers(id_cow); | ||||
sergey: That's a bit elaborate way of freeing an ID, and is always made me sad. Is there an easier way… | |||||
Done Inline ActionsThere are enough places in the code where freeing data and the python reference can't be paired up. Although it might be worth making these cases an exception, eg: BKE_libblock_free_data_ex(id, do_id_user, do_id_py_instance) Making BKE_libblock_free_data free both by default. Can be handled as a separate refactor. campbellbarton: There are enough places in the code where freeing data and the python reference can't be paired… | |||||
| BKE_libblock_free_data_py(id_cow); | |||||
| BKE_libblock_free_datablock(id_cow, 0); | BKE_libblock_free_datablock(id_cow, 0); | ||||
| BKE_libblock_free_data(id_cow, false); | BKE_libblock_free_data(id_cow, false); | ||||
| /* Signal datablock as not being expanded. */ | /* Signal datablock as not being expanded. */ | ||||
| id_cow->name[0] = '\0'; | id_cow->name[0] = '\0'; | ||||
| } | } | ||||
| void deg_evaluate_copy_on_write(struct ::Depsgraph *graph, const IDNode *id_node) | void deg_evaluate_copy_on_write(struct ::Depsgraph *graph, const IDNode *id_node) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines | |||||
That's a bit elaborate way of freeing an ID, and is always made me sad. Is there an easier way of completely freeing ID (and not the memory) than doing 3 calls?