Blender is crashed when the properties are dynamically created by bpy.types.CollectionProperty #84399

Closed
opened 2021-01-05 10:12:02 +01:00 by nutti · 8 comments
Member

System Information
Operating system: macOS 10.14.6
Graphics card: Radeon Pro 450

Blender Version
Broken: 2.91
Worked: 2.80

Short description of error

Blender is crashed when the properties are dynamically created by bpy.types.CollectionProperty .

I want to create an add-on which changes the number of bpy.types.BoolProperty dynamically along with the context.
But, Blender will crash when I changes the status of dynamically created checkbox.

NOTE: I doubt that this issue may come from the incorrect usage of bpy.types.CollectionProperty, but I'm not sure.

Exact steps for others to reproduce the error

I will attach the simple add-on which reproduces this error.

collection_prop.py

  • Install the attached add-on.
  • Enable add-on "Collection Property".
  • Click File > Import > Test Op.
  • From right most region, you can see the checkbox list labeled by the numbers

Click checkbox some times, then Blender will crash.

I will also attach the crash report.

blender.crash.txt

**System Information** Operating system: macOS 10.14.6 Graphics card: Radeon Pro 450 **Blender Version** Broken: 2.91 Worked: 2.80 **Short description of error** Blender is crashed when the properties are dynamically created by bpy.types.CollectionProperty . I want to create an add-on which changes the number of bpy.types.BoolProperty dynamically along with the context. But, Blender will crash when I changes the status of dynamically created checkbox. *NOTE: I doubt that this issue may come from the incorrect usage of bpy.types.CollectionProperty, but I'm not sure.* **Exact steps for others to reproduce the error** I will attach the simple add-on which reproduces this error. [collection_prop.py](https://archive.blender.org/developer/F9551174/collection_prop.py) - Install the attached add-on. - Enable add-on "Collection Property". - Click **File** > **Import** > **Test Op**. - From right most region, you can see the checkbox list labeled by the numbers # Click checkbox some times, then Blender will crash. I will also attach the crash report. [blender.crash.txt](https://archive.blender.org/developer/F9551182/blender.crash.txt)
Author
Member

Added subscriber: @nutti

Added subscriber: @nutti
Member

Added subscriber: @filedescriptor

Added subscriber: @filedescriptor
Member

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

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

I can reproduce the crash on 2.92.0 Alpha, branch: master, commit date: 2021-01-05 07:03, hash: 08f00f4f6e.

I can reproduce the crash on 2.92.0 Alpha, branch: master, commit date: 2021-01-05 07:03, hash: `08f00f4f6e`.

Added subscriber: @rjg

Added subscriber: @rjg

Changed status from 'Confirmed' to: 'Archived'

Changed status from 'Confirmed' to: 'Archived'

The issue appears to be that you are adding references to the items you're adding to another list which you then use to add the properties to the layout. This list is cleared in the draw function, possibly leading to invalid references. Additionally, you are clearing and adding to the CollectionProperty on every draw. This means even if it doesn't crash, you can't actually do anything useful with the properties because they are replaced on the next draw of the UI along with their value.

You can see this in the following version, which shouldn't crash but doesn't actually let you use the checkboxes.

import bpy
from bpy.props import CollectionProperty, BoolProperty
from bpy_extras.io_utils import ImportHelper


bl_info = {

"name": "Collection Property",
"author": "nutti",
"version": (1, 0, 0),
"blender": (2, 91, 0),
"location": "",
"description": "",
"support": "COMMUNITY",
"category": "UV"

}

class BoolPropertyCollection(bpy.types.PropertyGroup):

checked: BoolProperty(name="", default=True)



class TEST_OT_TestOp(bpy.types.Operator, ImportHelper):

bl_idname = "uv.test_op"
bl_label = "Test Op"
bl_description = "Test Operator"
bl_options = {'REGISTER', 'UNDO'}


bool_prop_collection: CollectionProperty(type=BoolPropertyCollection)


def draw(self, context):
layout = self.layout


  self.bool_prop_collection.clear()
  for i in range(200):
      item = self.bool_prop_collection.add()
      item.name = str(i)
      
  for d in self.bool_prop_collection:
      layout.prop(d, "checked", text=d["name"])

def execute(self, context):
return {'FINISHED'}

def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)


  return {'RUNNING_MODAL'}


def menu_fn(self, _):

layout = self.layout
layout.operator(TEST_OT_TestOp.bl_idname)



def register():

bpy.utils.register_class(BoolPropertyCollection)
bpy.utils.register_class(TEST_OT_TestOp)


bpy.types.TOPBAR_MT_file_import.append(menu_fn)



def unregister():

bpy.types.TOPBAR_MT_file_import.remove(menu_fn)


bpy.utils.unregister_class(TEST_OT_TestOp)
bpy.utils.unregister_class(BoolPropertyCollection)



if __name__ == "__main__":

register()

As far as I can see this is not a bug in Blender, just an issue with an improperly implemented script. For questions on script development I would suggest you ask questions on one of our [community websites ]], for instance https:*blender.stackexchange.com/ , https:*blenderartists.org/ or the [ https:*blender.chat/channel/support | #support channel on Blender chat .

The issue appears to be that you are adding references to the items you're adding to another list which you then use to add the properties to the layout. This list is cleared in the draw function, possibly leading to invalid references. Additionally, you are clearing and adding to the `CollectionProperty` on every draw. This means even if it doesn't crash, you can't actually do anything useful with the properties because they are replaced on the next draw of the UI along with their value. You can see this in the following version, which shouldn't crash but doesn't actually let you use the checkboxes. ```lines import bpy from bpy.props import CollectionProperty, BoolProperty from bpy_extras.io_utils import ImportHelper bl_info = { ``` "name": "Collection Property", "author": "nutti", "version": (1, 0, 0), "blender": (2, 91, 0), "location": "", "description": "", "support": "COMMUNITY", "category": "UV" ``` } class BoolPropertyCollection(bpy.types.PropertyGroup): ``` checked: BoolProperty(name="", default=True) ``` class TEST_OT_TestOp(bpy.types.Operator, ImportHelper): ``` bl_idname = "uv.test_op" bl_label = "Test Op" bl_description = "Test Operator" bl_options = {'REGISTER', 'UNDO'} ``` ``` bool_prop_collection: CollectionProperty(type=BoolPropertyCollection) ``` ``` def draw(self, context): layout = self.layout ``` ``` self.bool_prop_collection.clear() for i in range(200): item = self.bool_prop_collection.add() item.name = str(i) for d in self.bool_prop_collection: layout.prop(d, "checked", text=d["name"]) ``` ``` def execute(self, context): return {'FINISHED'} def invoke(self, context, event): wm = context.window_manager wm.fileselect_add(self) ``` ``` return {'RUNNING_MODAL'} ``` def menu_fn(self, _): ``` layout = self.layout layout.operator(TEST_OT_TestOp.bl_idname) ``` def register(): ``` bpy.utils.register_class(BoolPropertyCollection) bpy.utils.register_class(TEST_OT_TestOp) ``` ``` bpy.types.TOPBAR_MT_file_import.append(menu_fn) ``` def unregister(): ``` bpy.types.TOPBAR_MT_file_import.remove(menu_fn) ``` ``` bpy.utils.unregister_class(TEST_OT_TestOp) bpy.utils.unregister_class(BoolPropertyCollection) ``` if __name__ == "__main__": ``` register() ``` ``` As far as I can see this is not a bug in Blender, just an issue with an improperly implemented script. For questions on script development I would suggest you ask questions on one of our [community websites ]], for instance [[ https:*blender.stackexchange.com/ | Blender's StackExchange ]], [[ https:*blenderartists.org/ | blenderartists.org ]] or the [[ https:*blender.chat/channel/support | #support channel on Blender chat ](https:*www.blender.org/community/).
Author
Member

@rjg

Thanks!
I will redirect this question to the other place.

@rjg Thanks! I will redirect this question to the other place.
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
3 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#84399
No description provided.