ACCESS VIOLATION when changing workspace from python #129405

Open
opened 2024-10-26 04:03:22 +02:00 by michael campbell · 8 comments

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

Blender Version
Broken: version: 4.4.0 Alpha, branch: main, commit date: 2024-10-12 12:21, hash: 191b347f5813
Worked: (newest version of Blender that worked as expected)

Exact steps for others to reproduce the error
When using the below code in an operator (EXEC_DEFAULT), not a modal, Blender crashes with an access violation intermittently:

    workspace_name = 'BoobieGenerator'
    if bpy.context.window.workspace.name != workspace_name:
        if bpy.context.preferences.addons[__name__.split('.')[0]].preferences.Switch_Workspaces and workspace_name in bpy.data.workspaces:
            print('about to change workspace')
            bpy.context.window.workspace = bpy.data.workspaces[workspace_name]
            print('changed workspace')

The workspace is imported from another file via python. Perhaps this could be the cause? The crash doesn't happen immediately afterwards, it may successfully switch to the workspace several times before crashing. Here's the code used to successfully import the workspace:

def append_items(blend_file_name,inner_directory,asset_name,scene_name = None):
    blend_path = os.path.join(root,blend_file_name)
    try:        
        
        bpy.ops.wm.append(filepath= os.path.join(blend_path, inner_directory, asset_name),
                            directory= os.path.join(blend_path,inner_directory),
                            filename= asset_name,
                            set_fake=True,
                            do_reuse_local_id = True,
                            link=False,
                            use_recursive=True                                
                            )

        bpy.data.libraries.remove(bpy.data.libraries[blend_file_name])
            
    except Exception as e:
        if scene_name is not None:
            report_custom_error.store_error(scene_name,f'Failed to Append {asset_name}. ')
        else:
            print(f'failed to append assets {inner_directory}')
            print(e)
        return False
    return True


def append_workspace_if_necessary():
    if bpy.context.preferences.addons[__name__.split('.')[0]].preferences.Switch_Workspaces :        
        if workspace_name not in bpy.data.workspaces:
            append_items('assetsv2.blend','WorkSpace',workspace_name)
            print('appended workspace')

Additionally (unsure if related), when the access violation does not happen and the workspace changes successfully, bpy.context.screen.areas does not update to reflect the content of the workspace. For example, the workspace I'm changing to has two image editors, but the below code doesn't find any if the workspace has been changed to in the same operator execution.

for area in bpy.context.screen.areas:
            if area.type == 'IMAGE_EDITOR':
                found += 1
**System Information** Operating system: Windows-10-10.0.22631-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 4080 SUPER/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 561.09 **Blender Version** Broken: version: 4.4.0 Alpha, branch: main, commit date: 2024-10-12 12:21, hash: `191b347f5813` Worked: (newest version of Blender that worked as expected) **Exact steps for others to reproduce the error** When using the below code in an operator (EXEC_DEFAULT), not a modal, Blender crashes with an access violation intermittently: ```def switch_workspace_if_necessary(): workspace_name = 'BoobieGenerator' if bpy.context.window.workspace.name != workspace_name: if bpy.context.preferences.addons[__name__.split('.')[0]].preferences.Switch_Workspaces and workspace_name in bpy.data.workspaces: print('about to change workspace') bpy.context.window.workspace = bpy.data.workspaces[workspace_name] print('changed workspace') ``` The workspace is imported from another file via python. Perhaps this could be the cause? The crash doesn't happen immediately afterwards, it may successfully switch to the workspace several times before crashing. Here's the code used to successfully import the workspace: ``` def append_items(blend_file_name,inner_directory,asset_name,scene_name = None): blend_path = os.path.join(root,blend_file_name) try: bpy.ops.wm.append(filepath= os.path.join(blend_path, inner_directory, asset_name), directory= os.path.join(blend_path,inner_directory), filename= asset_name, set_fake=True, do_reuse_local_id = True, link=False, use_recursive=True ) bpy.data.libraries.remove(bpy.data.libraries[blend_file_name]) except Exception as e: if scene_name is not None: report_custom_error.store_error(scene_name,f'Failed to Append {asset_name}. ') else: print(f'failed to append assets {inner_directory}') print(e) return False return True def append_workspace_if_necessary(): if bpy.context.preferences.addons[__name__.split('.')[0]].preferences.Switch_Workspaces : if workspace_name not in bpy.data.workspaces: append_items('assetsv2.blend','WorkSpace',workspace_name) print('appended workspace') ``` Additionally (unsure if related), when the access violation does not happen and the workspace changes successfully, bpy.context.screen.areas does not update to reflect the content of the workspace. For example, the workspace I'm changing to has two image editors, but the below code doesn't find any if the workspace has been changed to in the same operator execution. ``` for area in bpy.context.screen.areas: if area.type == 'IMAGE_EDITOR': found += 1 ```
michael campbell added the
Status
Needs Triage
Severity
Normal
Type
Bug
labels 2024-10-26 04:03:22 +02:00
michael campbell changed title from ACCESS VIOLSATION when changing workspace from python to ACCESS VIOLATION when changing workspace from python 2024-10-26 04:16:01 +02:00
Member

Clearer instructions on how to reproduce the issue would be helpful. Can you please share it with us?

Just for the record, I did try to reproduce the issue by:

  • Opening Blender
  • Opening a text editor and pasting a modified version of your code into it (See code block below).
  • Ran the code
  • Switched back to the layout with the text editor and ran it again (Repeated roughly 30 times)
import bpy

workspace_name = 'Modeling'
if bpy.context.window.workspace.name != workspace_name:
    if workspace_name in bpy.data.workspaces:
        print('about to change workspace')
        bpy.context.window.workspace = bpy.data.workspaces[workspace_name]
        print('changed workspace')

System Information
Operating system: Windows-10-10.0.22631-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 4090/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 565.90
Blender version: 4.4.0 Alpha, branch: main, commit date: 2024-10-26 11:51, hash: e9298dced494

Clearer instructions on how to reproduce the issue would be helpful. Can you please share it with us? Just for the record, I did try to reproduce the issue by: - Opening Blender - Opening a text editor and pasting a modified version of your code into it (See code block below). - Ran the code - Switched back to the layout with the text editor and ran it again (Repeated roughly 30 times) ```python import bpy workspace_name = 'Modeling' if bpy.context.window.workspace.name != workspace_name: if workspace_name in bpy.data.workspaces: print('about to change workspace') bpy.context.window.workspace = bpy.data.workspaces[workspace_name] print('changed workspace') ``` --- **System Information** Operating system: Windows-10-10.0.22631-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 4090/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 565.90 Blender version: 4.4.0 Alpha, branch: main, commit date: 2024-10-26 11:51, hash: `e9298dced494`
Alaska added
Status
Needs Information from User
and removed
Status
Needs Triage
labels 2024-10-27 05:55:43 +01:00

Hi, thanks. I believe to replicate, the code I provided needs running from an addon (not extension) rather than the script editor, and requires all three things to happen within the single operator call:

  1. append the workspace from another blend file
  2. change workspace
  3. loop through the screen areas checking if the area is of type 'IMAGE_EDITOR' (this may be the actual cause, because the results are incorrect). Potentially the access violation is due to an out of range error, so the appended workspace should have more or less editors, and in my case the screen type searched for existed in the appended workspace, but not the workspace being swapped from.

I'm up against it currently, so don't have a spare moment for the next couple of weeks, but if you don't have a blank addon you can drop the code I provided into, I'll create an addon for you after that period 👍

Hi, thanks. I believe to replicate, the code I provided needs running from an addon (not extension) rather than the script editor, and requires all three things to happen within the single operator call: 1. append the workspace from another blend file 2. change workspace 3. loop through the screen areas checking if the area is of type 'IMAGE_EDITOR' (this may be the actual cause, because the results are incorrect). Potentially the access violation is due to an out of range error, so the appended workspace should have more or less editors, and in my case the screen type searched for existed in the appended workspace, but not the workspace being swapped from. I'm up against it currently, so don't have a spare moment for the next couple of weeks, but if you don't have a blank addon you can drop the code I provided into, I'll create an addon for you after that period 👍
Member

Thanks for the info. I will se to Needs Triage at the moment, but I'll take another look at it either tomorrow or later this week.

Thanks for the info. I will se to `Needs Triage` at the moment, but I'll take another look at it either tomorrow or later this week.
Alaska added
Status
Needs Triage
and removed
Status
Needs Information from User
labels 2024-10-27 14:35:07 +01:00
Member

the code I provided needs running from an addon

Hi, can we get .py or zip addon file? I believe you're importing workspace file with an operator written in add-on?

Sorry but steps are still not very clear to me :/

> the code I provided needs running from an addon Hi, can we get .py or zip addon file? I believe you're importing workspace file with an operator written in add-on? Sorry but steps are still not very clear to me :/
Pratik Borhade added
Status
Needs Information from User
and removed
Status
Needs Triage
labels 2024-11-05 05:23:38 +01:00

No problem. I should be able to get that created for you next week 👍

No problem. I should be able to get that created for you next week 👍
Member

Using the steps provided I created this addon and couldn't reproduce the issue.

Steps to use this addon:

  • Install the addon
  • In the 3D viewport select Object -> Simple Object Operator
Using the steps provided I created this addon and couldn't reproduce the issue. Steps to use this addon: - Install the addon - In the 3D viewport select `Object -> Simple Object Operator`
Member

Hi, any updates?

Hi, any updates?

Sorry I'm still flat out on another project. I'll test and modify Alaska's addon so that it generates the violation ASAP 👍

Sorry I'm still flat out on another project. I'll test and modify Alaska's addon so that it generates the violation ASAP 👍
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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#129405
No description provided.