Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2021-09-24 17:34:13 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-09-27 11:57:23 +0300
commit30ef197c7b57e2763f66abf21a4a148826c365f7 (patch)
tree111322b8e39b0ba4210b7b53e923a3a5e29f3c9f
parent617954c1438096810ce8e47f09c25c8311baac4d (diff)
Kernel: allow unregistering BKE callback functions
Introduce `BKE_callback_remove()`, which undoes the effect of `BKE_callback_add()`. It also respects `funcstore->alloc` by freeing the removed `funcstore` when needed. This allows for shorter-lived objects in memory to unregister their callbacks at the end of their lifespan. `BKE_callback_global_finalize()` has been adjusted so that the responsibility "remove a callback" is given to one function only. Reviewed by: campbellbarton Differential Revision: https://developer.blender.org/D12625
-rw-r--r--source/blender/blenkernel/BKE_callbacks.h1
-rw-r--r--source/blender/blenkernel/intern/callbacks.c14
2 files changed, 11 insertions, 4 deletions
diff --git a/source/blender/blenkernel/BKE_callbacks.h b/source/blender/blenkernel/BKE_callbacks.h
index ef2a0ed34a0..7c518f33c89 100644
--- a/source/blender/blenkernel/BKE_callbacks.h
+++ b/source/blender/blenkernel/BKE_callbacks.h
@@ -130,6 +130,7 @@ void BKE_callback_exec_id_depsgraph(struct Main *bmain,
struct Depsgraph *depsgraph,
eCbEvent evt);
void BKE_callback_add(bCallbackFuncStore *funcstore, eCbEvent evt);
+void BKE_callback_remove(bCallbackFuncStore *funcstore, eCbEvent evt);
void BKE_callback_global_init(void);
void BKE_callback_global_finalize(void);
diff --git a/source/blender/blenkernel/intern/callbacks.c b/source/blender/blenkernel/intern/callbacks.c
index 11ee9492b44..87d5961b12e 100644
--- a/source/blender/blenkernel/intern/callbacks.c
+++ b/source/blender/blenkernel/intern/callbacks.c
@@ -80,6 +80,15 @@ void BKE_callback_add(bCallbackFuncStore *funcstore, eCbEvent evt)
BLI_addtail(lb, funcstore);
}
+void BKE_callback_remove(bCallbackFuncStore *funcstore, eCbEvent evt)
+{
+ ListBase *lb = &callback_slots[evt];
+ BLI_remlink(lb, funcstore);
+ if (funcstore->alloc) {
+ MEM_freeN(funcstore);
+ }
+}
+
void BKE_callback_global_init(void)
{
/* do nothing */
@@ -95,10 +104,7 @@ void BKE_callback_global_finalize(void)
bCallbackFuncStore *funcstore_next;
for (funcstore = lb->first; funcstore; funcstore = funcstore_next) {
funcstore_next = funcstore->next;
- BLI_remlink(lb, funcstore);
- if (funcstore->alloc) {
- MEM_freeN(funcstore);
- }
+ BKE_callback_remove(funcstore, evt);
}
}
}