bpy.ops.render.render('INVOKE_DEFAULT') returns 'CANCELLED' during UI interaction #52258
Labels
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#52258
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
System Information
Windows 10 (64-Bit), GeForce GTX 1080 Ti
Blender Version
Broken: 2.78c
e92f235283
, 2.80.03ededb1
Short description of error
Using a modal operator to call bpy.ops.render.render('INVOKE_DEFAULT') multiple times, results in 'CANCELLED' return value as soon as the user interacts with the UI. This happens without modifying the scene in the python script and with each call to render being made after the previous render is finished.
The intention behind such a script (in an actual project) is to create multiple renders with motion blur, which have no temporal connection to each other.
An example would be soccer player kicking a ball, at many different positions on the field.
MWE_bug.blend
Exact steps for others to reproduce the error
Open the attached .blend file. The script is based on the one provided by Bastien Montagne (mont29) https://developer.blender.org/T32076
Alternatively you can also minimize and maximize the window.
Changed status to: 'Open'
Added subscriber: @rjg
This behavior can be reproduced on Linux (Ubuntu 64-Bit).
Can somebody verify whether this is intended behavior or actually a bug? I would greatly appreciate a workaround.
Added subscriber: @Sergey
Changed status from 'Open' to: 'Archived'
You are invoking one modal operator from another one.. This is a straight way to have all sort of weird and wonderful issues. This is not recommended to run operator from another one.
In any case, root of this particular issue is that render happens from a job (separate thread), and we don't allow two render jobs to be existing at the same time. However, since render works from a job, we call render_finished callback from that thread (this is the only place we can call it..). This might be seen by your script logic that system is ready for the next render, while it is not true since it might take some time to free remaining parts of render data and close job completely.
I'm not sure about reliable way of solving this problem, usually such tasks are done from a command line render script. You might try adding some delay after render_finish or re-try render later if 'CANCEL' is returned.
In any case, you're just stressing system to something it's not designed for.
Added subscriber: @mont29
What you described as root issue was pretty much what I imagined. Unfortunately the re-try idea doesn't work well, once it has returned 'CANCELLED' it's pretty much guaranteed to fail at subsequent attempts.
I haven't looked at the source at such a detailed level, but is there a particular reason why the callback isn't called after the (render) thread is joined?
Not sure if I missed something, but does the UI-button for rendering behave differently? Though it is unlikely that the user is clicking the button just as the render has finished, it should be causing the same problem.
The command line render script would be another option, but wouldn't give any benefit over calling bpy.ops.render.render() instead of bpy.ops.render.render('INVOKE_DEFAULT'). That was actually the main
reason that had me wondering if this is a bug, bpy.ops.render.render() works perfectly (though UI is not responsive). However that is due to not using a background thread. What is the correct way to call bpy.ops.render.render() (with whatever parameters)? The modal version was based on the code from @mont29, but apparently that is discouraged? If I'm not entirely mistaken every addon will (directly or indirectly) call it through another operator, since all buttons are operators.
Just do not use
'INVOKE_DEFAULT'
, which will launch it in modal mode, but rather'EXEC_DEFAULT'
, that way operation will be regular blocking one and will only return once render is actually finished.Yes that is what I was doing already. ‘EXEC_DEFAULT’ is used when no arguments are given. So the solution is to have no responsive/interactive UI and no preview.
I will take a look at the code. Perhaps this can be changed in future versions. It is very counter intuitive that the callback claims everything is done, but it isn't.
Callback says that rendering is done, as in there is final render and saved. It doesn't mean that render thread is destroyed (because callback is called from render thread). We do not have API to query whether particular thread is active is not.
I understood that. An API to check thread status would still be very useful.