GPv3: Fix bugs in find_layer_insertion_index() and some of its usages #113874

Closed
Douglas Paul wants to merge 2 commits from Douglas-Paul:fix-gpv3-layer-reordering-customdata-bugs into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Contributor

The recent PR #113852 fixed crashes by clamping the values returned by find_layer_insertion_index() to ensure they were not out of bounds, however the index being returned was still generally wrong. This would lead to the customdata being reordered incorrectly.

Specifically, the implementation of find_layer_insertion_index() was generally not returning the correct insertion index in the case where the target group was empty (i.e. the latter half of the function). This fixes those issues, as well as some issues in the way some callers were treating the returned index.


The first commit contains only the fixes with minimal restructuring, to make it easier to review the diff. The second commit is some refactoring to reduce redundancy and the risk of handling the insertion index incorrectly.

I included a lot of comments in the code to help explain the logic. I'm not attached to keeping them if they're too verbose.

I also pushed a third commit with copious debug logging to a separate branch. It's useful for local testing, but obviously not intended to be merged: fix-gpv3-layer-reordering-customdata-bugs-with-logging.

The attached .blend file is what I used for most of my testing. I temporarily saved it as my startup file to allow me to quickly start from a blank slate after each test.

The recent PR #113852 fixed crashes by clamping the values returned by find_layer_insertion_index() to ensure they were not out of bounds, however the index being returned was still generally wrong. This would lead to the customdata being reordered incorrectly. Specifically, the implementation of find_layer_insertion_index() was generally not returning the correct insertion index in the case where the target group was empty (i.e. the latter half of the function). This fixes those issues, as well as some issues in the way some callers were treating the returned index. --- The first commit contains only the fixes with minimal restructuring, to make it easier to review the diff. The second commit is some refactoring to reduce redundancy and the risk of handling the insertion index incorrectly. I included a lot of comments in the code to help explain the logic. I'm not attached to keeping them if they're too verbose. I also pushed a third commit with copious debug logging to a separate branch. It's useful for local testing, but obviously not intended to be merged: [fix-gpv3-layer-reordering-customdata-bugs-with-logging](https://projects.blender.org/Douglas-Paul/blender/commits/branch/fix-gpv3-layer-reordering-customdata-bugs-with-logging). The attached `.blend` file is what I used for most of my testing. I temporarily saved it as my startup file to allow me to quickly start from a blank slate after each test.
Douglas Paul added 2 commits 2023-10-18 07:50:43 +02:00
Iliya Katushenock added this to the Grease Pencil project 2023-10-18 08:26:49 +02:00
Falk David requested review from Falk David 2023-10-18 21:39:45 +02:00
Author
Contributor

Thanks for adding yourself as a reviewer, @filedescriptor. But FYI, I plan to file a new PR within the next couple days that would supersede this one, because I thought of a different approach for handling the custom data changes that I think will be much simpler to understand and maintain. So just in case you were planning to review this within the next couple days, you may want to hold off for now.

I will leave this PR open as a "fallback" in case my other PR isn't suitable or doesn't work out for some reason.

Thanks for adding yourself as a reviewer, @filedescriptor. But FYI, I plan to file a new PR within the next couple days that would supersede this one, because I thought of a different approach for handling the custom data changes that I think will be much simpler to understand and maintain. So just in case you were planning to review this within the next couple days, you may want to hold off for now. I will leave this PR open as a "fallback" in case my other PR isn't suitable or doesn't work out for some reason.
Member

@Douglas-Paul Would you mind sharing your idea in text form? Would be good to know about it before you jump into coding!

I already took a peek at this PR and I really like the way you restructured it (+1 for adding helpful comments too).

@Douglas-Paul Would you mind sharing your idea in text form? Would be good to know about it before you jump into coding! I already took a peek at this PR and I really like the way you restructured it (+1 for adding helpful comments too).
Author
Contributor

@filedescriptor I ended up jumping right into the coding anyway, because I'm not yet familiar enough with the codebase to have much confidence that an idea will work out. It also wasn't much work in this case.

Anyway, you'll find a description of the idea on the new PR, #113962. 🙂

@filedescriptor I ended up jumping right into the coding anyway, because I'm not yet familiar enough with the codebase to have much confidence that an idea will work out. It also wasn't much work in this case. Anyway, you'll find a description of the idea on the new PR, #113962. 🙂
Member

f5c9acc154 makes this PR now obsolete. Closing.

f5c9acc154 makes this PR now obsolete. Closing.
Falk David closed this pull request 2023-10-21 16:48:59 +02:00

Pull request closed

Sign in to join this conversation.
No reviewers
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
2 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#113874
No description provided.