Help tracking down hard crashes

Hi,

I made a python script, it seems to work well but sometimes it hard crashes and I have no idea why.

If I start the blender instance from the command line I see the error

“Error : EXCEPTION_ACCESS_VIOLATION”

Can anyone suggest how I can track it down?

The script is quite simple (although its in a file with more tools),

class ToggleAllCollections(bpy.types.Operator):
    bl_label = "F Toggle All Collections Visibility"
    bl_idname = "frankiestools.f_toggleallcollections"
    bl_description = "turn all collection visibility on"

    bpy.types.Scene.previously_active_collections_A = []
    bpy.types.Scene.previously_active_collections_B = []
    bpy.types.Scene.collections_all_visible = False

    def execute(self, context):
        ToggleAllCollections.toggle_hide(bpy.context.view_layer.layer_collection, bpy.types.Scene.collections_all_visible)
        return {"FINISHED"}

    def toggle_hide(view_layer, hide):
        if hide:
            bpy.types.Scene.collections_isolated = False
            for i in bpy.types.Scene.previously_active_collections_A:
                try:
                    i[0].hide_viewport = i[1]
                except:
                    print("error trying to unhide collection, but probably fine")
            for i in bpy.types.Scene.previously_active_collections_B:
                try:
                    i[0].hide_viewport = i[2]
                except:
                    print("error trying to unhide collection, but probably fine")
            bpy.types.Scene.collections_all_visible = False
            bpy.types.Scene.previously_active_collections_A = []
            bpy.types.Scene.previously_active_collections_B = []

        else:
            for i in view_layer.collection.children:
                bpy.types.Scene.previously_active_collections_A.append([i, i.hide_viewport])
                i.hide_viewport = False
            for i in view_layer.children:
                bpy.types.Scene.previously_active_collections_B.append([i, i.exclude, i.hide_viewport])
                i.hide_viewport = False
                if i.children:
                    ToggleAllCollections.toggle_hide(i, False)
            bpy.types.Scene.collections_all_visible = True

Thanks

you can’t cache data the way you’re doing it. between toggles in your operator, any number of memory operations might have happened that changed the address of the data you cached- you should either store the objects by name and then look them up again later, or use a pointer property.

This is all explained in greater detail here.

Thanks Testure, that was very helpful :+1: