Skip to content

Undo-Induced Crashes and Object Rotation Reset#12

Open
zvodd wants to merge 2 commits intoAIGODLIKE:developfrom
zvodd:develop
Open

Undo-Induced Crashes and Object Rotation Reset#12
zvodd wants to merge 2 commits intoAIGODLIKE:developfrom
zvodd:develop

Conversation

@zvodd
Copy link
Copy Markdown

@zvodd zvodd commented Feb 5, 2026

See #11
Fix UNDO related invalid object references causing blender to crash - Place Tool.
Fix intermited rotation loss when repicking objects - Place Tool

Refactor Memory Safety and Transform Logic
Summary This PR resolves stability issues by moving away from direct object references and fixes placement logic to preserve local object rotation.

  1. Stability Fix: String-Based Referencing
    Refactor _runtime.py: Replaced bpy.types.Object references with Object Names (strings).

Validation: Implemented a helper to fetch objects via context.scene.objects.get(name). This ensures that if an object is deleted or replaced during an Undo, the tool receives None instead of a corrupted pointer.

Undo Handler: Added a bpy.app.handlers.undo_post listener to clear _runtime.py caches, forcing the tool to re-evaluate the scene state safely after a database reload.

  1. Transformation Fix: Delta-Based Rotation
    Preserve Spin: Instead of reconstructing matrices from scratch in gzg.py, the gizmo matrix now uses the object's current matrix_world.to_quaternion() multiplied by the alignment offset.

Operator Logic: Updated op.py to calculate a "Rotation Offset" on invoke. During the modal loop, this offset is applied to the surface hit normal, allowing objects to maintain their local "spin" (e.g., a chair facing a specific direction) while still conforming to the floor/wall normal.

  1. Code Hygiene
    Migrated persistent state variables (like axis and invert_axis) into PlaceToolProps to ensure they are properly serialized and handled by Blender's native Undo system.

Place Tool (TODO other tools).
Fix intermited rotation loss when repicking objects - Place Tool
@xmx-emm
Copy link
Copy Markdown
Member

xmx-emm commented Feb 6, 2026

Thank you for your PR. It seems that this still needs further modification
I plan to change some of the functions to be driven by geometric nodes in the future
But I don't have much free time to complete it now, and there are many addons that need to be maintained:

@zvodd
Copy link
Copy Markdown
Author

zvodd commented Feb 8, 2026

Yes, sorry.
I introduced a new bug to place tool when dragging object over empty space.
This commit should fix, it. Though I have only done some limited testing.

For the above commit 77c9b17

Fix: Resolve crash when placing objects in empty space

This addresses a regression introduced by the recent fix for dangling pointer access.

The previous change, while fixing a memory issue, inadvertently created a new bug where the place tool would crash if the mouse cursor was moved over an empty area of the viewport. This occurred because a None object was being passed to functions expecting a valid Blender object when the raycast failed to find a surface.

This commit resolves the issue by ensuring the object placement logic is only executed when the raycast successfully hits a target. This not only prevents the crash but also provides a more stable user experience by keeping the object stationary when no valid surface is detected.

I understand you are busy, and not necessary able to actively maintain the project. It's cumbersome to review random pull request to small projects when you have many other projects. No pressure - feel free not to merge this pull request or review at your leasure.
I guess it's just here for reference of what modifications I have made to the plugin to make it work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants