BKE_callback_remove: prevent crash on Blender exit

`BKE_callback_remove` now checks whether the callback actually is known,
before trying to remove it.

`BKE_blender_atexit()` runs after `BKE_callback_global_finalize()`. When
an at-exit callback tried to unregister its BKE callbacks, these would
already be unregistered, causing a crash of Blender when exiting,
This commit is contained in:
Sybren A. Stüvel 2021-10-19 15:48:12 +02:00
parent 219058c213
commit a7075a30e2
1 changed files with 6 additions and 1 deletions

View File

@ -82,7 +82,12 @@ void BKE_callback_add(bCallbackFuncStore *funcstore, eCbEvent evt)
void BKE_callback_remove(bCallbackFuncStore *funcstore, eCbEvent evt)
{
ListBase *lb = &callback_slots[evt];
BLI_remlink(lb, funcstore);
/* Be safe, as the callback may have already been removed by BKE_callback_global_finalize(), for
* example when removing callbacks in response to a BKE_blender_atexit_register callback
* function. `BKE_blender_atexit()` runs after `BKE_callback_global_finalize()`. */
BLI_remlink_safe(lb, funcstore);
if (funcstore->alloc) {
MEM_freeN(funcstore);
}