Calling bpy_gizmo_target_set_value from python crashes blender if called from setup method #90634

Closed
opened 2021-08-12 15:05:08 +02:00 by Dan Rossner · 6 comments

System Information
Operating system: Windows 10
Graphics card: GeForce RTX 2060

Blender Version
Broken: 2.93.2 -> 3.0 latest alpha
Worked: (newest version of Blender that worked as expected)

Short description of error
The use of target_set_value causes inconsistent behavior when calling this method in python. On its own it seems to crash Blender, when being called on a gizmo in the Setup method of a GizmoGroup class. If previously the method target_set_handler is called, this will throw TypeError: Gizmo target property array, which implies these methods can't be used at the same time? Or whatever's causing the issue with target_set_value is conflicting with set_handler.

Exact steps for others to reproduce the error
Below is code for an addon that adds a toolshelf icon. Load this addon, and click on the toolshelf icon located in this image:

image.png

This will produce the crash. In the code I also commented areas of interest for different behavior such as the aformentioned TypeError.
Check the DummyWidget class for the source of the problem.

- This example adds an object mode tool to the toolbar.
- This is just the circle-select and lasso tools tool.
import bpy
from bpy.types import WorkSpaceTool

bl_info = {
    "name": "New Toolshelf Icon",
    "author": "Dan",
    "version": (1, 0, 0),
    "blender": (2, 93, 0),
    "description": "Adds a toolshelf icon",
    "category": "Object",
}


class ExampleScriptPress(bpy.types.Operator):
    bl_idname = "examplescript.mousepress"
    bl_label = 'Prevents tool from just doing "move" normally'

    @classmethod
    def poll(cls, context):
        return context.mode in {'OBJECT'}


class DummyWidget(bpy.types.GizmoGroup):
    bl_idname = "OBJECT_GGT_dummy_widget"
    bl_label = "Dummy widget"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'WINDOW'
    bl_options = {'3D'}

    @classmethod
    def poll(cls, context):
        return context.mode in {'OBJECT'}

    def setup(self, context):
        arrow1 = self.gizmos.new("GIZMO_GT_arrow_3d")
        arrow2 = self.gizmos.new("GIZMO_GT_arrow_3d")

        def move_get_x():
            return context.object.location.x

        def move_set_x(value):
            context.object.location.x = value
            print(arrow1.matrix_space)

        def move_get_y():
            return context.object.location.y

        def move_set_y(value):
            context.object.location.y = value

        - Using both set_handler and set_value causes an error.
        - Console output says "TypeError: Gizmo target property array"
        - Uncomment these to see for yourself. The rest of the code works as-is otherwise.
        - arrow1.target_set_handler("offset", get=move_get_x, set=move_set_x)
        arrow1.matrix_basis = context.object.matrix_world.normalized()

        #arrow2.target_set_handler("offset", get=move_get_y, set=move_set_y)
        arrow2.matrix_basis = context.object.matrix_world.normalized()

        - Here I wanted to see if this would throw an error, for debugging purposes.
        - Sure enough, it did.
        # These ALONE without set_handler will cause a crash.
        arrow1.target_set_value("offset", value=1.0)
        arrow1.target_set_value("offset", value=1.0)

        self.x_gizmo = arrow1
        self.y_gizmo = arrow2


    def refresh(self, context):
        self.x_gizmo.matrix_basis = context.object.matrix_world.normalized()
        self.y_gizmo.matrix_basis = context.object.matrix_world.normalized()
        
        - The original location of these methods before I started noticing problems
        - causes similar behavior as above.
        - arrow1.target_set_value("offset", value=1.0)
        - arrow1.target_set_value("offset", value=1.0)


classes = (
    ExampleScriptPress,
    DummyWidget,
)


class NewToolshelfClass(WorkSpaceTool):
    bl_space_type = 'VIEW_3D'
    bl_context_mode = 'OBJECT'

    bl_idname = "dan.newtoolshelf"
    bl_label = "New Toolshelf Icon"
    bl_options = {'REGISTER', 'UNDO'}
    bl_description = (
        "Adds a new toolshelf icon, with 2 arrow gizmos that change an object's position."
    )
    bl_icon = "ops.generic.select_circle"
    bl_widget = DummyWidget.bl_idname
    bl_keymap = (
        (ExampleScriptPress.bl_idname, {"type": 'LEFTMOUSE', "value": 'PRESS'},
         {"properties": []}
         ),
    )


def register():
    for cls in classes:
        bpy.utils.register_class(cls)
    bpy.utils.register_tool(NewToolshelfClass, after="builtin.transform", separator=True, group=True)


def unregister():
    bpy.utils.unregister_tool(NewToolshelfClass)
    for cls in classes:
        bpy.utils.unregister_class(cls)


if __name__ == "__main__":
    register()
**System Information** Operating system: Windows 10 Graphics card: GeForce RTX 2060 **Blender Version** Broken: **2.93.2** -> **3.0** latest alpha Worked: (newest version of Blender that worked as expected) **Short description of error** The use of `target_set_value` causes inconsistent behavior when calling this method in python. On its own it seems to crash Blender, when being called on a gizmo in the Setup method of a GizmoGroup class. If previously the method `target_set_handler` is called, this will throw `TypeError: Gizmo target property array`, which implies these methods can't be used at the same time? Or whatever's causing the issue with `target_set_value` is conflicting with set_handler. **Exact steps for others to reproduce the error** Below is code for an addon that adds a toolshelf icon. Load this addon, and click on the toolshelf icon located in this image: ![image.png](https://archive.blender.org/developer/F10278635/image.png) This will produce the crash. In the code I also commented areas of interest for different behavior such as the aformentioned TypeError. Check the DummyWidget class for the source of the problem. ``` - This example adds an object mode tool to the toolbar. - This is just the circle-select and lasso tools tool. import bpy from bpy.types import WorkSpaceTool bl_info = { "name": "New Toolshelf Icon", "author": "Dan", "version": (1, 0, 0), "blender": (2, 93, 0), "description": "Adds a toolshelf icon", "category": "Object", } class ExampleScriptPress(bpy.types.Operator): bl_idname = "examplescript.mousepress" bl_label = 'Prevents tool from just doing "move" normally' @classmethod def poll(cls, context): return context.mode in {'OBJECT'} class DummyWidget(bpy.types.GizmoGroup): bl_idname = "OBJECT_GGT_dummy_widget" bl_label = "Dummy widget" bl_space_type = 'VIEW_3D' bl_region_type = 'WINDOW' bl_options = {'3D'} @classmethod def poll(cls, context): return context.mode in {'OBJECT'} def setup(self, context): arrow1 = self.gizmos.new("GIZMO_GT_arrow_3d") arrow2 = self.gizmos.new("GIZMO_GT_arrow_3d") def move_get_x(): return context.object.location.x def move_set_x(value): context.object.location.x = value print(arrow1.matrix_space) def move_get_y(): return context.object.location.y def move_set_y(value): context.object.location.y = value - Using both set_handler and set_value causes an error. - Console output says "TypeError: Gizmo target property array" - Uncomment these to see for yourself. The rest of the code works as-is otherwise. - arrow1.target_set_handler("offset", get=move_get_x, set=move_set_x) arrow1.matrix_basis = context.object.matrix_world.normalized() #arrow2.target_set_handler("offset", get=move_get_y, set=move_set_y) arrow2.matrix_basis = context.object.matrix_world.normalized() - Here I wanted to see if this would throw an error, for debugging purposes. - Sure enough, it did. # These ALONE without set_handler will cause a crash. arrow1.target_set_value("offset", value=1.0) arrow1.target_set_value("offset", value=1.0) self.x_gizmo = arrow1 self.y_gizmo = arrow2 def refresh(self, context): self.x_gizmo.matrix_basis = context.object.matrix_world.normalized() self.y_gizmo.matrix_basis = context.object.matrix_world.normalized() - The original location of these methods before I started noticing problems - causes similar behavior as above. - arrow1.target_set_value("offset", value=1.0) - arrow1.target_set_value("offset", value=1.0) classes = ( ExampleScriptPress, DummyWidget, ) class NewToolshelfClass(WorkSpaceTool): bl_space_type = 'VIEW_3D' bl_context_mode = 'OBJECT' bl_idname = "dan.newtoolshelf" bl_label = "New Toolshelf Icon" bl_options = {'REGISTER', 'UNDO'} bl_description = ( "Adds a new toolshelf icon, with 2 arrow gizmos that change an object's position." ) bl_icon = "ops.generic.select_circle" bl_widget = DummyWidget.bl_idname bl_keymap = ( (ExampleScriptPress.bl_idname, {"type": 'LEFTMOUSE', "value": 'PRESS'}, {"properties": []} ), ) def register(): for cls in classes: bpy.utils.register_class(cls) bpy.utils.register_tool(NewToolshelfClass, after="builtin.transform", separator=True, group=True) def unregister(): bpy.utils.unregister_tool(NewToolshelfClass) for cls in classes: bpy.utils.unregister_class(cls) if __name__ == "__main__": register() ```
Author

Added subscriber: @ChimeraSSB

Added subscriber: @ChimeraSSB
Member

Added subscribers: @ideasman42, @lichtwerk

Added subscribers: @ideasman42, @lichtwerk
Member

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

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

Can confirm the crash.
Note that since c9d9bfa84a there is another issue with the WorkSpaceTool.setup() in this example

ValueError: WorkSpaceTool.setup(): error with keyword argument "options" - : 'UNDO' not found in ('KEYMAP_FALLBACK')

But commenting setting the options, we still get the crash.

I do think though that target_set_value is just not supposed to be called in the setup() -- seems like this belongs in the modal().
reason for the cras is that bpy_gizmo_target_set_value will try to find the "offset" property in your example (and it does), but this is not initialized fully at this point it seems (contains a NULL PropertyRNA prop)

@ideasman42 might know more.

Can confirm the crash. Note that since c9d9bfa84a there is another issue with the `WorkSpaceTool.setup()` in this example ``` ValueError: WorkSpaceTool.setup(): error with keyword argument "options" - : 'UNDO' not found in ('KEYMAP_FALLBACK') ``` But commenting setting the options, we still get the crash. I do think though that `target_set_value` is just not supposed to be called in the `setup()` -- seems like this belongs in the `modal()`. reason for the cras is that `bpy_gizmo_target_set_value` will try to find the "offset" property in your example (and it does), but this is not initialized fully at this point it seems (contains a NULL PropertyRNA prop) @ideasman42 might know more.
Campbell Barton self-assigned this 2021-09-29 09:29:45 +02:00

This issue was referenced by cc6ca13852

This issue was referenced by cc6ca1385279f4bd8817c8f23db40b3b43fa402b

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
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#90634
No description provided.