Crash using image resize operator with edit_image context override #97850

Closed
opened 2022-05-04 14:36:14 +02:00 by Mysteryem · 7 comments

System Information
Operating system: Windows 10

Blender Version
Broken: 2.91.0, 2.93.7, 3.0.0, 3.1.2

2.91.0 is the oldest version I have installed that has the image resize operator, I have not tested other versions in-between.

Short description of error
The bpy.ops.image.resize operator used with edit_image context override crashes Blender.

Expected behaviour
I would expect it to not crash Blender and that it would either:

  • Raise an error saying that the context is incorrect
    or
  • Perform the resize operation on the image specified in the context override.

Possible cause
I'm a little out of my depth reading the Blender source, but it appears to happen because the resize operator (called 'scale' in image_ops.c) requires a SpaceImage (bpy.types.SpaceImageEditor in the Python API) in context.space_data, but its poll function returns True when context.edit_image is a valid image even if context.space_data is not a valid SpaceImageEditor.

I'm guessing the poll function is currently shared between the image operators that require a SpaceImage and other image operators that do not require a SpaceImage.

Exact steps for others to reproduce the error
In the python console, run:

bpy.ops.image.resize({'edit_image': bpy.data.images.new('test_image', 32, 32)}, size=(16, 16))

Or copy and paste into text editor and run:

import bpy

width = 64
height = 64
name = 'test_image'
# Create a new image
image = bpy.data.images.new(name, width, height)
# Create the context override
context_override = {'edit_image': image}
new_size = (32, 32)

if bpy.ops.image.resize.poll(context_override):
    bpy.ops.image.resize(context_override, size=new_size)
**System Information** Operating system: Windows 10 **Blender Version** Broken: 2.91.0, 2.93.7, 3.0.0, 3.1.2 2.91.0 is the oldest version I have installed that has the image resize operator, I have not tested other versions in-between. **Short description of error** The `bpy.ops.image.resize` operator used with `edit_image` context override crashes Blender. **Expected behaviour** I would expect it to not crash Blender and that it would either: - Raise an error saying that the context is incorrect or - Perform the resize operation on the image specified in the context override. **Possible cause** I'm a little out of my depth reading the Blender source, but it appears to happen because the resize operator (called 'scale' in `image_ops.c`) requires a `SpaceImage` (`bpy.types.SpaceImageEditor` in the Python API) in `context.space_data`, but its `poll` function returns `True` when `context.edit_image` is a valid image even if `context.space_data` is not a valid `SpaceImageEditor`. I'm guessing the poll function is currently shared between the image operators that require a `SpaceImage` and other image operators that do not require a `SpaceImage`. **Exact steps for others to reproduce the error** In the python console, run: ``` bpy.ops.image.resize({'edit_image': bpy.data.images.new('test_image', 32, 32)}, size=(16, 16)) ``` Or copy and paste into text editor and run: ``` import bpy width = 64 height = 64 name = 'test_image' # Create a new image image = bpy.data.images.new(name, width, height) # Create the context override context_override = {'edit_image': image} new_size = (32, 32) if bpy.ops.image.resize.poll(context_override): bpy.ops.image.resize(context_override, size=new_size) ```
Author

Added subscriber: @Mysteryem-2

Added subscriber: @Mysteryem-2

Added subscriber: @rjg

Added subscriber: @rjg

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

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

The poll function could be modified, but image_scale_exec should definitely check if sima is NULL and cancel the operation if that is the case. This is already done for determining is_paint, but obviously needs to be the case whenever the pointer is dereferenced.

The poll function could be modified, but `image_scale_exec` should definitely check if `sima` is `NULL` and cancel the operation if that is the case. This is already done for determining `is_paint`, but obviously needs to be the case whenever the pointer is dereferenced.
Philipp Oeser removed the
Interest
Sculpt, Paint & Texture
label 2023-02-10 09:11:29 +01:00
Member

Overriding context changed a bit, so now you have to use

import bpy

width = 64
height = 64
name = 'test_image'
# Create a new image
image = bpy.data.images.new(name, width, height)

new_size = (32, 32)

with bpy.context.temp_override(edit_image=image):
    if bpy.ops.image.resize.poll():
        bpy.ops.image.resize(size=new_size)

Using that, I am not getting a crash anymore (I also dont see SpaceImage being used anymore other than for the is_paint check)

@Mysteryem-2 : can you confirm the crash is fixed for you in fresh builds from https://builder.blender.org/download/daily/ ?

Overriding context changed a bit, so now you have to use ``` import bpy width = 64 height = 64 name = 'test_image' # Create a new image image = bpy.data.images.new(name, width, height) new_size = (32, 32) with bpy.context.temp_override(edit_image=image): if bpy.ops.image.resize.poll(): bpy.ops.image.resize(size=new_size) ``` Using that, I am not getting a crash anymore (I also dont see `SpaceImage` being used anymore other than for the `is_paint` check) @Mysteryem-2 : can you confirm the crash is fixed for you in fresh builds from https://builder.blender.org/download/daily/ ?
Philipp Oeser added
Status
Needs Information from User
and removed
Status
Confirmed
labels 2024-02-28 13:54:59 +01:00
Member

The crash is fixed as of Blender 3.3.0 (crash still occurred up to 3.2.0) and the context override appears to work as expected.

The crash is fixed as of Blender 3.3.0 (crash still occurred up to 3.2.0) and the context override appears to work as expected.
Member

OKi, thx getting back!

Will close then.

OKi, thx getting back! Will close then.
Blender Bot added
Status
Archived
and removed
Status
Needs Information from User
labels 2024-02-28 14:43:15 +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
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#97850
No description provided.