Fix #92621: foreach_get/set doesn't work for enum #115508

Merged
Brecht Van Lommel merged 5 commits from Mysteryem/blender:fix_non_raw_enum_foreach_getset into main 2023-12-12 15:43:33 +01:00
Member

There were two issues at play here.

The first is that only enum properties with raw array access were
supported.

The second is that if the item property pointer was found immediately,
rna_raw_access could fall back to the slower loop without checking if
the property was an enum property, which the slower loop did not
support. This would cause the code to go through the entire slower loop
without doing anything. In the case of foreach_get without a
compatible buffer, this meant that the temporary, uninitialized array
(which was supposed to be set by rna_raw_access) would be converted to
Python integers, causing garbage values to be retrieved by
foreach_get, since they were created from uninitialized memory.

This patch adds support for enum properties that are not arrays and adds
asserts if an enum array property is encountered because they do not
exist.

Additional unreachable asserts have been added to the default case of
each switch block within the slower loop because there are prior checks
that the property type is supported, so the switch blocks should never
get an unsupported property type.


I'm not sure if enum array properties are even supported in general, in which case, it might be a good idea to add an assertion. edit: Asserts have been added and the PR description has been updated.

There were two issues at play here. The first is that only enum properties with raw array access were supported. The second is that if the item property pointer was found immediately, `rna_raw_access` could fall back to the slower loop without checking if the property was an enum property, which the slower loop did not support. This would cause the code to go through the entire slower loop without doing anything. In the case of `foreach_get` without a compatible buffer, this meant that the temporary, uninitialized array (which was supposed to be set by `rna_raw_access`) would be converted to Python integers, causing garbage values to be retrieved by `foreach_get`, since they were created from uninitialized memory. This patch adds support for enum properties that are not arrays and adds asserts if an enum array property is encountered because they do not exist. Additional unreachable asserts have been added to the default case of each switch block within the slower loop because there are prior checks that the property type is supported, so the switch blocks should never get an unsupported property type. --- ~~I'm not sure if enum array properties are even supported in general, in which case, it might be a good idea to add an assertion.~~ edit: Asserts have been added and the PR description has been updated.
Thomas Barlow added 1 commit 2023-11-28 07:19:42 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
c80bfb8c38
Fix #92621: foreach_get/set doesn't work for enum

@blender-bot build

@blender-bot build
Bastien Montagne approved these changes 2023-12-04 15:30:02 +01:00
Bastien Montagne left a comment
Owner

This LGTM, though would not mind having a second eye on it as well, @brecht or @ideasman42 ?

This LGTM, though would not mind having a second eye on it as well, @brecht or @ideasman42 ?
Bastien Montagne requested review from Brecht Van Lommel 2023-12-04 15:30:15 +01:00
Bastien Montagne requested review from Campbell Barton 2023-12-04 15:30:16 +01:00
Brecht Van Lommel requested changes 2023-12-04 15:39:26 +01:00
Brecht Van Lommel left a comment
Owner

Enum array properties do not exist, they can not be created with either the C or Python API.

That should be an assert rather than an error message.

Enum array properties do not exist, they can not be created with either the C or Python API. That should be an assert rather than an error message.
Thomas Barlow added 2 commits 2023-12-05 00:53:45 +01:00
Author
Member

I've replaced the enum array error messages with asserts.

I think I could also add BLI_assert_unreachable(); to the default case of each of the switch blocks?

I've replaced the enum array error messages with asserts. I think I could also add `BLI_assert_unreachable();` to the default case of each of the switch blocks?
Brecht Van Lommel approved these changes 2023-12-08 21:17:23 +01:00
Brecht Van Lommel left a comment
Owner

Adding BLI_assert_unreachable() as well sounds good.

Adding `BLI_assert_unreachable()` as well sounds good.
Thomas Barlow added 1 commit 2023-12-09 01:41:34 +01:00
Thomas Barlow added 1 commit 2023-12-09 01:42:04 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
fc19c360ed
Add BLI_assert_unreachable() to each switch block's default case
These should be unreachable because the property's type will already
have been checked for being a supported type and enum array properties
should not exist.
Brecht Van Lommel approved these changes 2023-12-11 11:24:35 +01:00
Bastien Montagne approved these changes 2023-12-11 12:02:25 +01:00

@blender-bot build

@blender-bot build
Brecht Van Lommel merged commit e503536775 into main 2023-12-12 15:43:33 +01:00
Brecht Van Lommel deleted branch fix_non_raw_enum_foreach_getset 2023-12-12 15:43:35 +01:00
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#115508
No description provided.