Skip to content

Commit

Permalink
Fix an issue in blender 4.0 when deleting objects in viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalillusions committed Nov 23, 2023
1 parent 066c431 commit f311188
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion bseq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
@persistent
def BSEQ_initialize(scene):
if update_obj not in bpy.app.handlers.frame_change_post:
bpy.app.handlers.frame_change_post.append(update_obj)
if auto_refresh_active not in bpy.app.handlers.frame_change_post:
bpy.app.handlers.frame_change_post.append(auto_refresh_active)
if auto_refresh_all not in bpy.app.handlers.frame_change_post:
bpy.app.handlers.frame_change_post.append(auto_refresh_all)
bpy.app.handlers.frame_change_post.append(update_obj)
if clean_unused_bseq_data not in bpy.app.handlers.save_pre:
bpy.app.handlers.save_pre.append(clean_unused_bseq_data)
subscribe_to_selected()
if print_information not in bpy.app.handlers.render_init:
bpy.app.handlers.render_init.append(print_information)
Expand Down
12 changes: 11 additions & 1 deletion bseq/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,14 @@ def auto_refresh_active(scene, depsgraph=None):
continue
if obj.mode != "OBJECT":
continue
refresh_obj(obj, scene)
refresh_obj(obj, scene)

# This becomes necessary, because when deleting objects from the viewport, they dont actually get removed from the
# sequences list, because this is not a global delete. This handler only removes sequences that are not referenced
# in any scene or collection. This handler is added to save_pre, so that unused data blocks dont get saved
def clean_unused_bseq_data(savefile):
for obj in bpy.data.objects:
if obj.BSEQ.init and len(obj.users_collection)==0 and len(obj.users_scene)==0:

# This will throw an error if it is actually still used somewhere
bpy.data.objects.remove(obj)
2 changes: 1 addition & 1 deletion bseq/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def filter_items(self, context, data, property):
# not sure if I understand correctly about this
# see reference from https://docs.blender.org/api/current/bpy.types.UIList.html#advanced-uilist-example-filtering-and-reordering
for o in objs:
if o.BSEQ.init:
if o.BSEQ.init and len(o.users_collection)>0 and len(o.users_scene)>0:
flt_flags.append(self.bitflag_filter_item)
else:
flt_flags.append(0)
Expand Down

0 comments on commit f311188

Please sign in to comment.