Call "bpy.ops.screen.screen_full_area()" 2 times causes EXCEPTION_ACCESS_VIOLATION #78968

Closed
opened 2020-07-16 06:35:53 +02:00 by hyyou · 8 comments

System Information
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: GeForce RTX 2060/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 432.00

Blender Version
Broken: version: 2.83.0, branch: master, commit date: 2020-06-03 14:38, hash: 211b6c29f7
Worked: None

Short description of error
In text editor, the below code work fines :-

override = {'window': window, 'screen': screen, 'area': area}
bpy.ops.screen.screen_full_area(override)
#bpy.ops.screen.screen_full_area(override) 

However, if I uncomment the line, Blender will crash.

Exact steps for others to reproduce the error
Try to run this script :-

import os.path
import bpy

print("=========BEGIN ====")
str_contextName='VIEW_3D'
bool_found = False
for window in bpy.context.window_manager.windows:
    screen = window.screen
    for area in screen.areas:
        if area.type == str_contextName:
            print(" ==> found context ")
            bpy.context.window.scene = bpy.context.scene
            override = {'window': window, 'screen': screen, 'area': area}
            bpy.ops.screen.screen_full_area(override)
            bpy.ops.screen.screen_full_area(override) #: try to uncomment = crash
            #^ will get "exception_access_violation" when exit this XXX.py 
            bool_found=True
            break
    
print("=========END====")
**System Information** Operating system: Windows-10-10.0.19041-SP0 64 Bits Graphics card: GeForce RTX 2060/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 432.00 **Blender Version** Broken: version: 2.83.0, branch: master, commit date: 2020-06-03 14:38, hash: `211b6c29f7` Worked: None **Short description of error** In text editor, the below code work fines :- ``` override = {'window': window, 'screen': screen, 'area': area} bpy.ops.screen.screen_full_area(override) #bpy.ops.screen.screen_full_area(override) ``` However, if I uncomment the line, Blender will crash. **Exact steps for others to reproduce the error** Try to run this script :- ``` import os.path import bpy print("=========BEGIN ====") str_contextName='VIEW_3D' bool_found = False for window in bpy.context.window_manager.windows: screen = window.screen for area in screen.areas: if area.type == str_contextName: print(" ==> found context ") bpy.context.window.scene = bpy.context.scene override = {'window': window, 'screen': screen, 'area': area} bpy.ops.screen.screen_full_area(override) bpy.ops.screen.screen_full_area(override) #: try to uncomment = crash #^ will get "exception_access_violation" when exit this XXX.py bool_found=True break print("=========END====") ```
Author

Added subscriber: @hyyou

Added subscriber: @hyyou

Added subscriber: @mano-wii

Added subscriber: @mano-wii

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

This is related to the same problem described in #77419
Solving that problem will probably solve this one too.

But even without working as it should, the crash should be replaced with an error message.
Just as it should be in #54468

This is related to the same problem described in #77419 Solving that problem will probably solve this one too. But even without working as it should, the crash should be replaced with an error message. Just as it should be in #54468

Added subscriber: @ideasman42

Added subscriber: @ideasman42

Looked into a fix, although the root of the error is that the area & screen being passed on the second call are invalid (freed memory).

A more general fix for this would be to validate all context members passed as overrides to operators from Python, to properly raise errors, as doing this from the operator would end up causing checks all over.

Once valid data is passed to the operator, this patch makes the functionality possible.

diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c
index f534296bd0b..230970bed81 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -1259,6 +1259,7 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *area, const
     oldscreen = WM_window_get_active_screen(win); /* the one disappearing */
 
     BLI_assert(BKE_workspace_layout_screen_get(layout_old) != screen);
+    BLI_assert(BKE_workspace_layout_screen_get(layout_old) == oldscreen);
     BLI_assert(BKE_workspace_layout_screen_get(layout_old)->state != SCREENNORMAL);
 
     screen->state = SCREENNORMAL;
@@ -1312,6 +1313,8 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *area, const
      * Without doing so, the screen handling gets wrong area coords,
      * which in worst case can lead to crashes (see T43139) */
     screen->skip_handling = true;
+
+    WM_window_set_active_screen(win, workspace, screen);
   }
   else {
     /* change from SCREENNORMAL to new state */
@@ -1378,7 +1381,11 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *area, const
     ED_screen_change(C, screen);
   }
 
+  BLI_assert(workspace = WM_window_get_active_workspace(win));
+  BLI_assert(win == CTX_wm_window(C));
+
   /* XXX bad code: setscreen() ends with first area active. fullscreen render assumes this too */
+  CTX_wm_screen_set(C, screen);
   CTX_wm_area_set(C, screen->areabase.first);
 
   return screen->areabase.first;
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index aff19ddacf1..cc2152d6bfd 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -3162,7 +3162,8 @@ static void SCREEN_OT_screen_set(wmOperatorType *ot)
 /* function to be called outside UI context, or for redo */
 static int screen_maximize_area_exec(bContext *C, wmOperator *op)
 {
-  bScreen *screen = CTX_wm_screen(C);
+  wmWindow *win = CTX_wm_window(C);
+  bScreen *screen = WM_window_get_active_screen(win);
   ScrArea *area = NULL;
   const bool hide_panels = RNA_boolean_get(op->ptr, "use_hide_panels");
 
@@ -3183,13 +3184,13 @@ static int screen_maximize_area_exec(bContext *C, wmOperator *op)
     if (!ELEM(screen->state, SCREENNORMAL, SCREENFULL)) {
       return OPERATOR_CANCELLED;
     }
-    ED_screen_state_toggle(C, CTX_wm_window(C), area, SCREENFULL);
+    ED_screen_state_toggle(C, win, area, SCREENFULL);
   }
   else {
     if (!ELEM(screen->state, SCREENNORMAL, SCREENMAXIMIZED)) {
       return OPERATOR_CANCELLED;
     }
-    ED_screen_state_toggle(C, CTX_wm_window(C), area, SCREENMAXIMIZED);
+    ED_screen_state_toggle(C, win, area, SCREENMAXIMIZED);
   }
 
   return OPERATOR_FINISHED;
Looked into a fix, although the root of the error is that the area & screen being passed on the second call are invalid (freed memory). A more general fix for this would be to validate all context members passed as overrides to operators from Python, to properly raise errors, as doing this from the operator would end up causing checks all over. Once valid data is passed to the operator, this patch makes the functionality possible. ``` diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index f534296bd0b..230970bed81 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -1259,6 +1259,7 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *area, const oldscreen = WM_window_get_active_screen(win); /* the one disappearing */ BLI_assert(BKE_workspace_layout_screen_get(layout_old) != screen); + BLI_assert(BKE_workspace_layout_screen_get(layout_old) == oldscreen); BLI_assert(BKE_workspace_layout_screen_get(layout_old)->state != SCREENNORMAL); screen->state = SCREENNORMAL; @@ -1312,6 +1313,8 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *area, const * Without doing so, the screen handling gets wrong area coords, * which in worst case can lead to crashes (see T43139) */ screen->skip_handling = true; + + WM_window_set_active_screen(win, workspace, screen); } else { /* change from SCREENNORMAL to new state */ @@ -1378,7 +1381,11 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *area, const ED_screen_change(C, screen); } + BLI_assert(workspace = WM_window_get_active_workspace(win)); + BLI_assert(win == CTX_wm_window(C)); + /* XXX bad code: setscreen() ends with first area active. fullscreen render assumes this too */ + CTX_wm_screen_set(C, screen); CTX_wm_area_set(C, screen->areabase.first); return screen->areabase.first; diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index aff19ddacf1..cc2152d6bfd 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -3162,7 +3162,8 @@ static void SCREEN_OT_screen_set(wmOperatorType *ot) /* function to be called outside UI context, or for redo */ static int screen_maximize_area_exec(bContext *C, wmOperator *op) { - bScreen *screen = CTX_wm_screen(C); + wmWindow *win = CTX_wm_window(C); + bScreen *screen = WM_window_get_active_screen(win); ScrArea *area = NULL; const bool hide_panels = RNA_boolean_get(op->ptr, "use_hide_panels"); @@ -3183,13 +3184,13 @@ static int screen_maximize_area_exec(bContext *C, wmOperator *op) if (!ELEM(screen->state, SCREENNORMAL, SCREENFULL)) { return OPERATOR_CANCELLED; } - ED_screen_state_toggle(C, CTX_wm_window(C), area, SCREENFULL); + ED_screen_state_toggle(C, win, area, SCREENFULL); } else { if (!ELEM(screen->state, SCREENNORMAL, SCREENMAXIMIZED)) { return OPERATOR_CANCELLED; } - ED_screen_state_toggle(C, CTX_wm_window(C), area, SCREENMAXIMIZED); + ED_screen_state_toggle(C, win, area, SCREENMAXIMIZED); } return OPERATOR_FINISHED; ```

Changed status from 'Confirmed' to: 'Archived'

Changed status from 'Confirmed' to: 'Archived'
Campbell Barton self-assigned this 2020-09-23 08:05:19 +02:00

Closing this report as screen_full_area sets a new screen and area which is needed for the second call to works as expected.

This works:

import os.path
import bpy

print("=========BEGIN ====")
str_contextName='VIEW_3D'
bool_found = False
for window in bpy.context.window_manager.windows:
    screen = window.screen
    for area in screen.areas:
        if area.type == str_contextName:
            print(" ==> found context A")
            bpy.context.window.scene = bpy.context.scene
            override = {'window': window, 'screen': screen, 'area': area}
            bpy.ops.screen.screen_full_area(override)
            break
    screen = window.screen
    for area in screen.areas:
        if area.type == str_contextName:
            print(" ==> found context B")
            override = {'window': window, 'screen': screen, 'area': area}
            bpy.ops.screen.screen_full_area(override)
            break
print("=========END====")
Closing this report as `screen_full_area` sets a new screen and area which is needed for the second call to works as expected. This works: ``` import os.path import bpy print("=========BEGIN ====") str_contextName='VIEW_3D' bool_found = False for window in bpy.context.window_manager.windows: screen = window.screen for area in screen.areas: if area.type == str_contextName: print(" ==> found context A") bpy.context.window.scene = bpy.context.scene override = {'window': window, 'screen': screen, 'area': area} bpy.ops.screen.screen_full_area(override) break screen = window.screen for area in screen.areas: if area.type == str_contextName: print(" ==> found context B") override = {'window': window, 'screen': screen, 'area': area} bpy.ops.screen.screen_full_area(override) break print("=========END====") ```
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#78968
No description provided.