Crash when calling UNDO from a python script #28724
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#28724
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?
%%%Blender uses to crash when I export some objects/meshes with an import/export python addon I've written.
Plugin structure:
I'm roughly using the following structure when exporting:
To sum up, the goal is to export the meshes' faces and vertices once they are tranformed by the modifers, scale factor, etc. (I don't know a better way to proceed than applying all transformations before exporting the data...)
Issue:
Blender uses to crash when I export some scenes with this plugin. It does not crash systematically, for example with the scene I'm supplying here, it crashes after 3 runs. With simpler scene (ie. not using modifiers, etc.), it never crashes.
As a note, I know when it's going to crash as Blender slows down and I hear my hdd suddenly getting busy (as if the OS is trying to swap memory, though the memory consumption remains quite stable - see the attached screenshot, Blender's Private Byte was around 50MB when it crashed - and there was not other running apps).
Steps to reproduce:
(I've attached a bare bones version of the plugin and a test scene, both are enough to trigger a crash on my system)
Workaround:
If I remove the "bpy.ops.ed.undo()" command from the addon and manually use the Ctrl+Z shortcut each time after running the addon, it works as expected and Blender never crashes.
%%%
Changed status to: 'Open'
%%%While this shouldn't crash,
Using undo in python isn't going to work well, you're most likely better off to make a copy, modify that, then throw it away.
or... not even copy it - you can just multiply the vertex location by the object.matrix_world to get their worldspace locations on export.
Like this:
wco = obj.matrix_world * vertex.co
%%%
%%%Thanks for the world matrix tip, Campbell. I was aware of this solution, but it can't fit for a simple reason: we don't get the full mesh as soon as a modifier is used (even a simple but heavily used one like mirror).
In the early development of this plugin, I was using dummy copies, as you also suggested. But as far as I remember, it was not very efficient. And deleting objects still leaves a lot of junk meshes as long as Blender is not restarted (though I think we can now delete them directly from python API).
Too bad. Any shot term / long term improvement foreseeable, or is it definitely hopeless?
A really nice solution would be to have a python way to access the meshes exactly as there are displayed in the scene (ie. after modifiers, scale, etc.) as those data are necessarily somewhere in memory. But I know this is not the place for feature request...
And if there's any test I could conduce or any process I should follow to help you locate the bug, please don't hesitate.%%%
%%%The most most common way to deal with it:
mesh = obj.to_mesh(scene, True, 'PREVIEW')
... export mesh data ...
bpy.data.meshes.remove(mesh)
see export_ply.py which comes with blender for the full example.
Undo is documented to be problematic with scripts: http://www.blender.org/documentation/blender_python_api_2_59_3/info_gotcha.html#undo-redo
Closing.%%%
Changed status from 'Open' to: 'Archived'
%%%I was unaware of the Python API Gotchas document, which actually holds very valuable info.
Thanks a lot for pointing me out to the right direction.%%%
Changed status from 'Archived' to: 'Resolved'