From 0f1ee611d4499fbac050b7a997e50bc234a252f9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 24 Apr 2021 23:31:07 +1000 Subject: Fix T85567: Crash accessing gizmo group on `__del__` - Re-order freeing so an instances __del__ method runs before the `ExtensionRNA` has been freed. - "remove" functions no longer free the gizmo/gizmo-group memory, needed so the identifier used when freeing the extension doesn't use the freed identifier. --- source/blender/makesrna/intern/rna_wm_gizmo.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'source/blender/makesrna/intern/rna_wm_gizmo.c') diff --git a/source/blender/makesrna/intern/rna_wm_gizmo.c b/source/blender/makesrna/intern/rna_wm_gizmo.c index f7d139dd706..e91df38c96e 100644 --- a/source/blender/makesrna/intern/rna_wm_gizmo.c +++ b/source/blender/makesrna/intern/rna_wm_gizmo.c @@ -534,12 +534,16 @@ static void rna_Gizmo_unregister(struct Main *bmain, StructRNA *type) return; } + WM_gizmotype_remove_ptr(NULL, bmain, gzt); + + /* Free extension after removing instances so `__del__` doesn't crash, see: T85567. */ RNA_struct_free_extension(type, &gzt->rna_ext); RNA_struct_free(&BLENDER_RNA, type); - WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL); + /* Free gizmo group after the extension as it owns the identifier memory. */ + WM_gizmotype_free_ptr(gzt); - WM_gizmotype_remove_ptr(NULL, bmain, gzt); + WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL); } static void **rna_Gizmo_instance(PointerRNA *ptr) @@ -934,12 +938,16 @@ static void rna_GizmoGroup_unregister(struct Main *bmain, StructRNA *type) return; } + WM_gizmo_group_type_remove_ptr(bmain, gzgt); + + /* Free extension after removing instances so `__del__` doesn't crash, see: T85567. */ RNA_struct_free_extension(type, &gzgt->rna_ext); RNA_struct_free(&BLENDER_RNA, type); - WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL); + /* Free gizmo group after the extension as it owns the identifier memory. */ + WM_gizmo_group_type_free_ptr(gzgt); - WM_gizmo_group_type_remove_ptr(bmain, gzgt); + WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL); } static void **rna_GizmoGroup_instance(PointerRNA *ptr) -- cgit v1.2.3