get selected bone in blender python is inconsistent #53135
Labels
No Label
Interest
Animation & Rigging
Interest
Blender Cloud
Interest
Collada
Interest
Core
Interest
Documentation
Interest
Eevee & Viewport
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
Import and Export
Interest
Modeling
Interest
Modifiers
Interest
Nodes & Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds, Tests & Devices
Interest
Python API
Interest
Rendering & Cycles
Interest
Sculpt, Paint & Texture
Interest
Translations
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Meta
Good First Issue
Meta
Papercut
Module
Add-ons (BF-Blender)
Module
Add-ons (Community)
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
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender-addons#53135
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
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
Win 7 64 bits
Blender Version
official 2.79
hash 5bd8ac9
Short description of error
When I print the selected bone in python, the result is wrong when a command switch back and force to pose mode.
Exact steps for others to reproduce the error
Based on a (as simple as possible) attached .blend file with minimum amount of steps
New blend file
create a bone, go to edit mode
extrude a few times (let's say 8)
select the first bone.
launch this script a few times :
import bpy
C = bpy.context
selBone = C.selected_bones[0]
print (selBone)
bpy.ops.object.mode_set(mode='POSE')
bpy.ops.object.mode_set(mode='EDIT')
print (selBone)
sometimes console will print "Bone" and sometimes "Bone.008"
I found this bug using the addon "Auto Bone Controller" which crashed when doing funny things in pose mode and edit mode.
Changed status to: 'Open'
Added subscriber: @sarazinjean-francois
Added subscriber: @JoshuaLeung
Changed status from 'Open' to: 'Archived'
This is an unavoidable dangling pointers/references bug that we cannot ever fully fix:
selBone = C.selected_bones- [x]
line grabs a reference to an EditBone. This then gets invalidated on the first mode-change. Python has no way to know this of course, and we can't really do anything about this (at least not without significant slowdowns)To fix these problems, don't hang on to pointers to data before/after mode changes. Instead, store the name of the bone instead, and look up the new bone instance using that name.
For example, your script should be changed to look more like:
Hope that helps
thanks a lot Joshua. I wasn't aware that getting a selection was a pointer. I'll try to propose a change to the addon with the work around you proposed.