Page MenuHome

Python - in an operator, setting scene frame after undo causes playback cursor to get 'stuck'
Closed, ResolvedPublic

Description

System Information
Windows 8.1

Blender Version
Broken: 2.79b

Short description of error
Ok, this is kinda hard to describe, so here goes -
If a scene's sync mode is "AV-sync",
If an operator is called from a panel,
The operator runs an undo operation (bpy.ops.ed.undo()),
Then setting bpy.context.scene.frame_current will cause the playback cursor to get stuck rapidly iterating between 2 frames.

This seems to only happen if it is done in an operator, and only if the operator is called from a panel or shortcut (not just directly in the script run), and only if the av-sync is set

Exact steps for others to reproduce the error
Set a new scene's sync mode to "AV-sync"
Load the following script into a text area
Run the script
Click the new "Test" button in the "Test Panel" panel in the 3d view properties panel.

import bpy

class TestOperator(bpy.types.Operator):
    bl_idname = "test.operator"
    bl_label = "Test"

    def invoke(self, context, event):
        bpy.ops.screen.animation_play()
        bpy.ops.ed.undo_push()
        bpy.ops.ed.undo()
        context.scene.frame_current = 1  #unfortunately, this makes blender spaz out and get stuck on the frame...
        return {'FINISHED'}

class TestPanel(bpy.types.Panel):
    bl_label = "Test Panel"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    
    def draw(self, context):
        self.layout.operator("test.operator")

def register():
    bpy.utils.register_class(TestOperator)
    bpy.utils.register_class(TestPanel)

if __name__ == "__main__":
    register()

Details

Type
Bug

Event Timeline

As a side note, I have seen this happen before from some other cause, but it was one of those unreproducable 'what the heck just happened??' moments...
So, it is entirely possible that other combinations of commands may cause this, but Blender was most definitely set to av-sync mode in that situation.

Bastien Montagne (mont29) closed this task as Resolved.
Bastien Montagne (mont29) claimed this task.
Bastien Montagne (mont29) triaged this task as Normal priority.

Fwiw, on 2.8 it seems to work OK, so will consider that issue as fixed. Thanks for the report!