bpy.ops.text.reload with overridden contxet crashes blender #113644

Open
opened 2023-10-13 09:04:33 +02:00 by Andrej · 4 comments
Contributor

Blender 3.6.4

Was trying to revive the old script for reloading text editor if file has changed and found that bpy.ops.text.reload with overridden crashes blender.

Steps to reproduce:

  1. New blender session, open scripting tab
  2. Open some test.py from your computer in text editor and change it outside blender so it will be need a reload.
  3. Run the code below.
  4. You can comment out bpy.ops.text.reload(context_override) to see that there is a same issue with temp_override.
context_override = {} 
context_override["edit_text"] = bpy.data.texts["test.py"]
area = next(area for area in bpy.context.screen.areas if area.type == "TEXT_EDITOR")
space = next(space for space in area.spaces if space.type == "TEXT_EDITOR")
context_override["space_data"] = space

print('old override method')
bpy.ops.text.reload(context_override)

print('new override method')
with bpy.context.temp_override(**context_override):
    bpy.ops.text.reload()

Also the same issue with text.resolve_conflict.

print('old override method')
bpy.ops.text.resolve_conflict(context_override, resolution="RELOAD")

print('new override method')
with bpy.context.temp_override(**context_override):
    bpy.ops.text.resolve_conflict(resolution="RELOAD")

Current workaround for me was to reload the data manually.

# using reloading operators causes crashes, therefore we reload the text manually
# saving text to file afterwards as it's the only way to flip `.is_modified`
# since reload doesn't work - https://projects.blender.org/blender/blender/issues/113644
with open(text.filepath, 'r') as fi:
    new_text = fi.read()
text.from_string(new_text)

def get_area():
    for screen in bpy.data.screens:
        for area in screen.areas:
            if area.type == "TEXT_EDITOR":
                return area
            
context_override = {} 
context_override["edit_text"] = text
space = next(space for space in get_area().spaces if space.type == "TEXT_EDITOR")
context_override["space_data"] = space

with bpy.context.temp_override(**context_override):
    bpy.ops.text.save()
Blender 3.6.4 Was trying to revive the [old script for reloading text editor](https://archive.blender.org/wiki/index.php/Extensions:2.5/Py/Scripts/Text_Editor/Reload_if_Modified/) if file has changed and found that `bpy.ops.text.reload` with overridden crashes blender. Steps to reproduce: 1) New blender session, open scripting tab 2) Open some `test.py` from your computer in text editor and change it outside blender so it will be need a reload. 3) Run the code below. 4) You can comment out `bpy.ops.text.reload(context_override)` to see that there is a same issue with `temp_override`. ```python context_override = {} context_override["edit_text"] = bpy.data.texts["test.py"] area = next(area for area in bpy.context.screen.areas if area.type == "TEXT_EDITOR") space = next(space for space in area.spaces if space.type == "TEXT_EDITOR") context_override["space_data"] = space print('old override method') bpy.ops.text.reload(context_override) print('new override method') with bpy.context.temp_override(**context_override): bpy.ops.text.reload() ``` Also the same issue with `text.resolve_conflict`. ```python print('old override method') bpy.ops.text.resolve_conflict(context_override, resolution="RELOAD") print('new override method') with bpy.context.temp_override(**context_override): bpy.ops.text.resolve_conflict(resolution="RELOAD") ``` Current workaround for me was to reload the data manually. ```python # using reloading operators causes crashes, therefore we reload the text manually # saving text to file afterwards as it's the only way to flip `.is_modified` # since reload doesn't work - https://projects.blender.org/blender/blender/issues/113644 with open(text.filepath, 'r') as fi: new_text = fi.read() text.from_string(new_text) def get_area(): for screen in bpy.data.screens: for area in screen.areas: if area.type == "TEXT_EDITOR": return area context_override = {} context_override["edit_text"] = text space = next(space for space in get_area().spaces if space.type == "TEXT_EDITOR") context_override["space_data"] = space with bpy.context.temp_override(**context_override): bpy.ops.text.save() ```
Andrej added the
Priority
Normal
Status
Needs Triage
Type
Report
labels 2023-10-13 09:04:34 +02:00
Member

The with bpy.context.temp_override(**context_override): method seems to be working as it should in 4.1

3.6 also works here, could you try find the crash log?

The `with bpy.context.temp_override(**context_override):` method seems to be working as it should in 4.1 3.6 also works here, could you try find the crash log?
YimingWu added
Status
Needs Information from User
and removed
Status
Needs Triage
labels 2023-10-13 11:38:43 +02:00
Author
Contributor

Attached the crash log.

Tested it now also with --factory-startup to make sure it's unrelated to any addons.

Attached the crash log. Tested it now also with `--factory-startup` to make sure it's unrelated to any addons.
Member

Interesting, thanks, let me see what exactly is wrong on that version.

Interesting, thanks, let me see what exactly is wrong on that version.

All versions seem to crash for me, inside the same function text_reload_exec (3.6, 3.5, 3.3, and 2.93 even)

Will confirm

All versions seem to crash for me, inside the same function `text_reload_exec` (3.6, 3.5, 3.3, and 2.93 even) Will confirm
Jesse Yurkovich added
Module
Python API
Status
Confirmed
and removed
Status
Needs Information from User
labels 2023-10-13 21:32:04 +02: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#113644
No description provided.