Hello,
I’m new to Blender coding and currently I’m fixing an issue #112683 I’ve raised myself.
Apparently, I’ve managed to fix this, but I thought I’d ask here about some details first before creating the pull request.
GPencil data block bGPdata is created on the first stroke, as well as the default layer ‘Note’. After deleting that single layer, bGPdata isn’t deleted and is accessed through Tool Options header drawing code, producing those warnings in the console. I’ve fixed it by freeing bGPdata when the last annotation layer is deleted.
What I’m wondering about is the following. bGPdata is allocated by BKE_libblock_alloc(), but there is no BKE_libblock_free(), even though it is mentioned somewhere in a comment in blender\blenkernel\intern\lib_id.cc. So instead I used BKE_libblock_management_main_remove() (which btw hasn’t been used anywhere so far!) followed by MEM_freeN().
This is the fix which I put at the end of the gpencil_layer_remove_exec():
/* If we removed the last layer for annotations, free the current GPencil block. */
if (is_annotation && gpd->layers.first == nullptr) {
BKE_gpencil_free_data(gpd, true);
Main *bmain = CTX_data_main(C);
BKE_libblock_management_main_remove(bmain, gpd);
MEM_freeN(gpd);
bGPdata **gpd_ptr = ED_annotation_data_get_pointers(C, nullptr);
*gpd_ptr = nullptr;
}
This seems to work just fine, but I’d appreciete some advice on this.
Regards,
Milan