Crash with python api 'spaces[0].deselect_all() on Windows #119312

Closed
opened 2024-03-11 07:33:19 +01:00 by yonghao lv · 5 comments

System Information
Operating system: Windows-10-10.0.22621-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 4080/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 546.33

Blender Version
Broken: version: 4.0.2, branch: blender-v4.0-release, commit date: 2023-12-05 07:41, hash: 9be62e85b727
Worked: crash on windows, work well on mac

Short description of error
See crash.txt

Exact steps for others to reproduce the error
run script with this addon enable https://github.com/AIGODLIKE/ComfyUI-BlenderAI-node (not found depsgraph_update_post in it)

import bpy
from bpy.app.handlers import persistent

G_ACTIVE_MATS_LIST = []  

@persistent
def update_active_object_material(scene, depsgraph):
    if not hasattr(bpy.context, 'object'):
        return
    elif bpy.context.object is None:
        return
    elif bpy.context.object.type not in {'MESH', 'CURVE', 'FONT', 'META', 'VOLUME', 'GPENCIL', 'SURFACE'}:
        return
    elif len(bpy.context.object.material_slots) == 0:
        return

    asset_area = None
    for area in bpy.context.window.screen.areas:
        if area.type == 'FILE_BROWSER' and area.ui_type == 'ASSETS':
            asset_area = area
            break

    if asset_area is None: return

    global G_ACTIVE_MATS_LIST
    G_ACTIVE_MATS_LIST.clear()

    for mat_slot in bpy.context.object.material_slots:
        G_ACTIVE_MATS_LIST.append(mat_slot.material)
    try:
        asset_area.spaces[0].deselect_all() # crash here
        if bpy.context.object.select_get():
            for mat in G_ACTIVE_MATS_LIST:
                asset_area.spaces[0].activate_asset_by_id(mat, deferred=False) # and here
    except Exception as e:
        print(e)

bpy.app.handlers.depsgraph_update_post.append(update_active_object_material)
**System Information** Operating system: Windows-10-10.0.22621-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 4080/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 546.33 **Blender Version** Broken: version: 4.0.2, branch: blender-v4.0-release, commit date: 2023-12-05 07:41, hash: `9be62e85b727` Worked: crash on windows, work well on mac **Short description of error** See crash.txt **Exact steps for others to reproduce the error** run script with this addon enable https://github.com/AIGODLIKE/ComfyUI-BlenderAI-node (not found depsgraph_update_post in it) ```Py import bpy from bpy.app.handlers import persistent G_ACTIVE_MATS_LIST = [] @persistent def update_active_object_material(scene, depsgraph): if not hasattr(bpy.context, 'object'): return elif bpy.context.object is None: return elif bpy.context.object.type not in {'MESH', 'CURVE', 'FONT', 'META', 'VOLUME', 'GPENCIL', 'SURFACE'}: return elif len(bpy.context.object.material_slots) == 0: return asset_area = None for area in bpy.context.window.screen.areas: if area.type == 'FILE_BROWSER' and area.ui_type == 'ASSETS': asset_area = area break if asset_area is None: return global G_ACTIVE_MATS_LIST G_ACTIVE_MATS_LIST.clear() for mat_slot in bpy.context.object.material_slots: G_ACTIVE_MATS_LIST.append(mat_slot.material) try: asset_area.spaces[0].deselect_all() # crash here if bpy.context.object.select_get(): for mat in G_ACTIVE_MATS_LIST: asset_area.spaces[0].activate_asset_by_id(mat, deferred=False) # and here except Exception as e: print(e) bpy.app.handlers.depsgraph_update_post.append(update_active_object_material) ```
yonghao lv added the
Type
Report
Priority
Normal
Status
Needs Triage
labels 2024-03-11 07:33:20 +01:00
yonghao lv changed title from Crash with python api 'spaces[0].deselect_all() to Crash with python api 'spaces[0].deselect_all() on Windows 2024-03-11 07:52:23 +01:00
Iliya Katushenock added the
Interest
Python API
label 2024-03-11 10:12:42 +01:00

Thanks for report, 1: i can not install add-on without errors in the terminal (see addon error.txt), 2: i can not run your script without error (see script error.txt).
Please, simplify steps to reproduce bug (no one will spend time to deep into the addon code) to be able to run just small script and get the crash.

Thanks for report, 1: i can not install add-on without errors in the terminal (see `addon error.txt`), 2: i can not run your script without error (see `script error.txt`). Please, simplify steps to reproduce bug (no one will spend time to deep into the addon code) to be able to run just small script and get the crash.
Author

Thanks for report, 1: i can not install add-on without errors in the terminal (see addon error.txt), 2: i can not run your script without error (see script error.txt).
Please, simplify steps to reproduce bug (no one will spend time to deep into the addon code) to be able to run just small script and get the crash.

ok. I will check it later. It is hard to find out where cause the crash. The crash report only give this line and nothing else.

> Thanks for report, 1: i can not install add-on without errors in the terminal (see `addon error.txt`), 2: i can not run your script without error (see `script error.txt`). > Please, simplify steps to reproduce bug (no one will spend time to deep into the addon code) to be able to run just small script and get the crash. ok. I will check it later. It is hard to find out where cause the crash. The crash report only give this line and nothing else.

In fact, having to install a complex third-party addon seems like a lot for a bug report that should present a problem in the Blender code.

We require the bug reporter to narrow down the problem.

Since the code snippet shows depsgraph_update_post, I suspect it must be related to the same issue described in #118223?

(Maybe by changing some Material, it triggers another depsgraph update, while the drawing code is using an older (freed) evaluated data?)

In fact, having to install a complex third-party addon seems like a lot for a bug report that should present a problem in the Blender code. We require the bug reporter to narrow down the problem. Since the code snippet shows `depsgraph_update_post`, I suspect it must be related to the same issue described in #118223? (Maybe by changing some Material, it triggers another depsgraph update, while the drawing code is using an older (freed) evaluated data?)
Germano Cavalcante added
Status
Needs Information from User
and removed
Status
Needs Triage
labels 2024-03-12 18:58:06 +01:00
Author

still not find where cause the crash. but I think this may happen when a scene init.
I use some hack to turn on the handle later so it won't crash

@bpy.app.handlers.persistent
def update_active_object_material(scene, depsgraph):
    wm = bpy.context.window_manager
    if wm.mathp_update_active_obj_mats is False: # custom parm to control handle
        return
   # crash code here
    asset_area = None
        for area in bpy.context.window.screen.areas:
            if area.type == 'FILE_BROWSER' and area.ui_type == 'ASSETS':
                asset_area = area
                break
    if asset_area is None: return
    asset_area.spaces[0].deselect_all() 


def register_later(lock, t):
    import time
    while not hasattr(bpy.context, 'scene'):
        time.sleep(5)
    wm = bpy.context.window_manager
    wm.mathp_update_active_obj_mats = True # custom parm to control handle

def register():
    bpy.types.WindowManager.mathp_update_active_obj_mats = bpy.props.BoolProperty(name='Select Active Object Materials',
                                                                        description="If checked, the active object's materials will be automatically selected",
                                                                        default=False)
    import threading
    lock = threading.Lock()
    lock_holder = threading.Thread(target=register_later, args=(lock, 5), name='Init_Scene2')
    lock_holder.daemon = True
    lock_holder.start()
still not find where cause the crash. but I think this may happen when a scene init. I use some hack to turn on the handle later so it won't crash ```python @bpy.app.handlers.persistent def update_active_object_material(scene, depsgraph): wm = bpy.context.window_manager if wm.mathp_update_active_obj_mats is False: # custom parm to control handle return # crash code here asset_area = None for area in bpy.context.window.screen.areas: if area.type == 'FILE_BROWSER' and area.ui_type == 'ASSETS': asset_area = area break if asset_area is None: return asset_area.spaces[0].deselect_all() def register_later(lock, t): import time while not hasattr(bpy.context, 'scene'): time.sleep(5) wm = bpy.context.window_manager wm.mathp_update_active_obj_mats = True # custom parm to control handle def register(): bpy.types.WindowManager.mathp_update_active_obj_mats = bpy.props.BoolProperty(name='Select Active Object Materials', description="If checked, the active object's materials will be automatically selected", default=False) import threading lock = threading.Lock() lock_holder = threading.Thread(target=register_later, args=(lock, 5), name='Init_Scene2') lock_holder.daemon = True lock_holder.start() ```

No activity for more than a week. As per the tracker policy we assume the issue is gone and can be closed.

Unfortunately this scenario is still too complex for us to track down, we require the bug reporter to narrow down the problem.

For now I will consider it as a possible duplicate of #118223

No activity for more than a week. As per the tracker policy we assume the issue is gone and can be closed. Unfortunately this scenario is still too complex for us to track down, we require the bug reporter to narrow down the problem. For now I will consider it as a possible duplicate of #118223
Blender Bot added
Status
Archived
and removed
Status
Needs Information from User
labels 2024-03-25 16:04:10 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#119312
No description provided.