Regression: Python API: 'bpy.ops.screen.area_close' crashes in Blender 4.1 #119202

Closed
opened 2024-03-08 12:36:23 +01:00 by Alex Zhornyak · 4 comments

System Information
Operating system: Windows-10-10.0.22621-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 3050 Ti Laptop GPU/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 546.26

Blender Version
Broken: version: 4.1.0 Alpha, branch: main, commit date: 2023-12-09 00:52, hash: 76bf43f44d0c
Worked: version: 4.1.0 Alpha, branch: main, commit date: 2023-11-24 00:19, hash: 23430f4db868

Caused by 6af92e1360

Short description of error
bpy.ops.screen.area_close function crashes in Blender 4.1

Exact steps for others to reproduce the error

  1. Open test_close_areas_in_sequence.blend
  2. Run Script in Scripting workspace

Expected:
All areas except Text Editor should be closed

Result:
Blender crashes always: test_close_areas_in_sequence.crash.txt

**System Information** Operating system: Windows-10-10.0.22621-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 3050 Ti Laptop GPU/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 546.26 **Blender Version** Broken: version: 4.1.0 Alpha, branch: main, commit date: 2023-12-09 00:52, hash: `76bf43f44d0c` Worked: version: 4.1.0 Alpha, branch: main, commit date: 2023-11-24 00:19, hash: `23430f4db868` Caused by 6af92e13607bde4cdaccba0f280e7a5219725cbf **Short description of error** `bpy.ops.screen.area_close` function crashes in Blender 4.1 **Exact steps for others to reproduce the error** 1. Open [test_close_areas_in_sequence.blend](/attachments/50c405fc-db0c-4f36-a272-8e9bd647f2fd) 2. Run Script in Scripting workspace **Expected:** All areas except Text Editor should be closed **Result:** Blender crashes always: [test_close_areas_in_sequence.crash.txt](/attachments/84ed6e7e-18d5-484f-9c11-588a10e5f00d)
Alex Zhornyak added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2024-03-08 12:36:24 +01:00
Iliya Katushenock changed title from Python API: 'bpy.ops.screen.area_close' crashes in Blender 4.1 to Regression: Python API: 'bpy.ops.screen.area_close' crashes in Blender 4.1 2024-03-08 12:46:55 +01:00
Iliya Katushenock added this to the 4.1 milestone 2024-03-08 13:01:47 +01:00

Can confirm issue both in 4.1 and 4.0 branches, but this make sense to note worked/broken versions only for 4.1 so i did more accurate bisect and note only such versions.

Can confirm issue both in 4.1 and 4.0 branches, but this make sense to note worked/broken versions only for 4.1 so i did more accurate bisect and note only such versions.
Member

Narrowed it down a bit to

2023-12-04 good 153f14be2b
2023-12-08 bad 2b0448c91d

Will bisect.

Narrowed it down a bit to 2023-12-04 good 153f14be2b67 2023-12-08 bad 2b0448c91d7a Will bisect.
Member

Caused by 6af92e1360

CC @ideasman42

Caused by 6af92e13607bde4cdaccba0f280e7a5219725cbf CC @ideasman42
Philipp Oeser added the
Interest
User Interface
label 2024-03-08 16:04:19 +01:00
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2024-03-11 07:37:56 +01:00

@azhornyak committed a fix however a minor change to the script was needed, see set once.

What's happening is SCREEN_OT_area_close is clearing the context.

This clearing makes a permanent change to the context which the temporary context manager doesn't restore, because doing so makes it impossible to run operators which intentionally change the context, see: #117188.

Having the area clear the context was change in 9290b41381 so the event loop wouldn't attempt to handle events in an area that had been removed.

import bpy

ctx = bpy.context
screen = ctx.screen  # <-- set once.

p_areas = {area for area in ctx.screen.areas if area.ui_type != 'TEXT_EDITOR'}
for area in p_areas:
    override = {}
    override['screen'] = screen
    override['window'] = ctx.window_manager.windows[0]
    override['area'] = area

    with bpy.context.temp_override(**override):
        if bpy.ops.screen.area_close.poll():
            bpy.ops.screen.area_close()

@azhornyak committed a fix however a minor change to the script was needed, see `set once`. What's happening is `SCREEN_OT_area_close` is clearing the context. This clearing makes a permanent change to the context which the temporary context manager doesn't restore, because doing so makes it impossible to run operators which intentionally change the context, see: #117188. Having the area clear the context was change in 9290b41381fdf02d1431b216de6477f93b2897cb so the event loop wouldn't attempt to handle events in an area that had been removed. ``` import bpy ctx = bpy.context screen = ctx.screen # <-- set once. p_areas = {area for area in ctx.screen.areas if area.ui_type != 'TEXT_EDITOR'} for area in p_areas: override = {} override['screen'] = screen override['window'] = ctx.window_manager.windows[0] override['area'] = area with bpy.context.temp_override(**override): if bpy.ops.screen.area_close.poll(): bpy.ops.screen.area_close() ```
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
4 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#119202
No description provided.