UI widget for pointer property with custom type causes segmentation fault #52735

Closed
opened 2017-09-13 23:00:05 +02:00 by Peter Noble · 14 comments

System Information
Ubuntu 17.04 64 bit + Win 10 64 bit

Blender Version
Broken: 2.79

Short description of error
Creating a UI widget to edit a pointer property that was created with type specified as a subclass of bpy.types.ID declared in Python (rather than one of the pre-existing subclasses) causes a segmentation fault when trying to edit.

Exact steps for others to reproduce the error
Run the following script. Editing the first property in the popup (points to bpy.types.NodeTree) acts as expected. Editing the second property in the popup (points to bpy.types.TestTreeType) causes a segmentation fault.

import bpy

class CustomNodeTree(bpy.types.NodeTree):
    bl_idname = "TestTreeType"
    bl_label = "Test tree"
    bl_icon = "PLUGIN"

def draw(self, context):
    self.layout.prop(context.scene, "testNodeTreeProp")
    self.layout.prop(context.scene, "testCustomProp")

bpy.utils.register_class(CustomNodeTree)
bpy.types.Scene.testNodeTreeProp = bpy.props.PointerProperty(type=bpy.types.NodeTree)
bpy.types.Scene.testCustomProp = bpy.props.PointerProperty(type=bpy.types.TestTreeType)
bpy.context.window_manager.popup_menu(draw)
**System Information** Ubuntu 17.04 64 bit + Win 10 64 bit **Blender Version** Broken: 2.79 **Short description of error** Creating a UI widget to edit a pointer property that was created with type specified as a subclass of bpy.types.ID declared in Python (rather than one of the pre-existing subclasses) causes a segmentation fault when trying to edit. **Exact steps for others to reproduce the error** Run the following script. Editing the first property in the popup (points to bpy.types.NodeTree) acts as expected. Editing the second property in the popup (points to bpy.types.TestTreeType) causes a segmentation fault. ``` import bpy class CustomNodeTree(bpy.types.NodeTree): bl_idname = "TestTreeType" bl_label = "Test tree" bl_icon = "PLUGIN" def draw(self, context): self.layout.prop(context.scene, "testNodeTreeProp") self.layout.prop(context.scene, "testCustomProp") bpy.utils.register_class(CustomNodeTree) bpy.types.Scene.testNodeTreeProp = bpy.props.PointerProperty(type=bpy.types.NodeTree) bpy.types.Scene.testCustomProp = bpy.props.PointerProperty(type=bpy.types.TestTreeType) bpy.context.window_manager.popup_menu(draw) ```
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @PeterNoble

Added subscriber: @PeterNoble

Added subscribers: @mont29, @Sergey

Added subscribers: @mont29, @Sergey
Bastien Montagne was assigned by Sergey Sharybin 2017-09-14 09:42:04 +02:00

@mont29, is it something related on recent ID custom properties implemented for 2.79?

@mont29, is it something related on recent ID custom properties implemented for 2.79?

@Sergey yes, but… wait… since when is it valid to subclass an ID type? Subclassing ID types in Python… who ever allowed such an evil scheme? :((((((

This is for sure not going to work with ID custom props, not with current code anyway… type here shall always be real ID one, not some fancy py subclassing. Will check on code, this should be possible to validate at prop definition time.

@Sergey yes, but… wait… since when is it valid to subclass an ID type? Subclassing ID types in Python… who ever allowed such an evil scheme? :(((((( This is for sure not going to work with ID custom props, not with current code anyway… `type` here shall always be real ID one, not some fancy py subclassing. Will check on code, this should be possible to validate at prop definition time.

@mont29, isn't it how custom node trees are supposed to work? You kind of subclass there.
Would be nice to at least prevent crashes, perhaps.

@mont29, isn't it how custom node trees are supposed to work? You kind of subclass there. Would be nice to at least prevent crashes, perhaps.

Added subscriber: @ideasman42

Added subscriber: @ideasman42

Ok… still, don’t think that was a good idea, like, at all… ID types are not virtual stuff like operators or render engines, they are data, stored in Blender file, they are kind of root of everything in Blender, so faking their subclassing in py sounds like a nice can of worms to me… Would have been so much cleaner to have registrable NodeTreeType classes instead! Anyway…

Crash happens because automated search button generation code (ui_but_add_search()) cannot find a proper ID collection for the type of subclassed nodetree, and hence does not call UI_but_func_search_set() for created button, which later when entering 'edit mode' of that button tries to call but->search_create_func(), which is NULL.

So we actually have two issues here, one fail in UI code to safely handle case where searchprop of a searchmenu is not valid (will fix, it's pretty trivial).

And the subclass-of-real-ID case, here I would just forbid any non-real-ID class… and curse to death that very idea of ID subclassing! :( @ideasman42 may have better ideas here though?

Ok… still, don’t think that was a good idea, like, at all… ID types are not virtual stuff like operators or render engines, they are **data**, stored in Blender file, they are kind of root of everything in Blender, so faking their subclassing in py sounds like a nice can of worms to me… Would have been so much cleaner to have registrable NodeTreeType classes instead! Anyway… Crash happens because automated search button generation code (`ui_but_add_search()`) cannot find a proper ID collection for the type of subclassed nodetree, and hence does not call `UI_but_func_search_set()` for created button, which later when entering 'edit mode' of that button tries to call `but->search_create_func()`, which is NULL. So we actually have two issues here, one fail in UI code to safely handle case where searchprop of a searchmenu is not valid (will fix, it's pretty trivial). And the subclass-of-real-ID case, here I would just forbid any non-real-ID class… and curse to death that very idea of ID subclassing! :( @ideasman42 may have better ideas here though?
Author

Maybe I've got the wrong idea but the impression I got was that this change to PointerProperty was useful because it allowed search boxes to be more specific than just materials, objects, node trees etc... I can't think of any reason the user would ever need a search box that allows selecting of all node tree types but it would be useful to only allow a specific type of node group.

Other than the UI bit it acts as expected when using the PointerProperty from other Python code. It allows data blocks of the correct type to be assigned and in this case, for example, it doesn't allow a node group that isn't of type TestTreeType.

Maybe I've got the wrong idea but the impression I got was that this change to PointerProperty was useful because it allowed search boxes to be more specific than just materials, objects, node trees etc... I can't think of any reason the user would ever need a search box that allows selecting of all node tree types but it would be useful to only allow a specific type of node group. Other than the UI bit it acts as expected when using the PointerProperty from other Python code. It allows data blocks of the correct type to be assigned and in this case, for example, it doesn't allow a node group that isn't of type TestTreeType.

Added subscriber: @BYOB

Added subscriber: @BYOB

I recently stumbled about this bug as well, so I can confirm it.

I avoid the crash by setting the type to PointerProperty(type=bpy.types.NodeTree), but then a user gets a dropdown where he can select any type of nodetree in the scene.
Basically the same issue:

I can't think of any reason the user would ever need a search box that allows selecting of all node tree types but it would be useful to only allow a specific type of node group.

But that's slightly offtopic I guess.

I recently stumbled about this bug as well, so I can confirm it. I avoid the crash by setting the type to `PointerProperty(type=bpy.types.NodeTree)`, but then a user gets a dropdown where he can select any type of nodetree in the scene. Basically the same issue: > I can't think of any reason the user would ever need a search box that allows selecting of all node tree types but it would be useful to only allow a specific type of node group. But that's slightly offtopic I guess.
Bastien Montagne was unassigned by Dalai Felinto 2019-12-23 16:36:31 +01:00
Member

Added subscriber: @Blendify

Added subscriber: @Blendify
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Aaron Carlisle self-assigned this 2020-01-24 03:07:44 +01:00
Member

This should be fixed

This should be fixed
Sign in to join this conversation.
No Milestone
No project
No Assignees
5 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-addons#52735
No description provided.