Fix #121169: asserts in curve geometry code. #122441

Merged
Bastien Montagne merged 2 commits from mont29/blender:tmp-fix-curves-geometry-asserts into main 2024-05-30 10:24:19 +02:00

Asserts triggered e.g. by opening Gold production files (like
pro/shots/220_storm/220_0020/220_0020-anim.blend). Their root cause
are zero tangent vectors.

The asserts initially came from unormalized normals, but the root issue
is actually using zero vector as axis in calls to
math::rotate_direction_around_axis.

While rotating a zero direction vector is possible (though useless),
rotating around a zero axis vector makes no sense?

So this commit adds an assert that the given axis is non-zero in
rotate_direction_around_axis. And 'fixes' the found cases triggering
such assert by skipping rotation when the axis (tangent) is null.

Another related issue fixed by this commit is the iterative process in
calls to calculate_next_normal, which can accumulate small floating
point errors over time, leading to generating not normalized-enough
normals at some point.

Some questions:

  • Should we have an epsilon-based check for zero vector, instead of
    relying on 'exaclty zero' check? For tangents, since they are assumed
    normalized, it does not matter that much, but in general this may be a
    better option? Could not find any is_almost_zero helper though.
  • In the specific cases fixed here, is it best to skip rotation when the
    tangent is null, or should we rather try to use the previous tangent
    e.g.?
Asserts triggered e.g. by opening Gold production files (like `pro/shots/220_storm/220_0020/220_0020-anim.blend`). Their root cause are zero tangent vectors. The asserts initially came from unormalized normals, but the root issue is actually using zero vector as axis in calls to `math::rotate_direction_around_axis`. While rotating a zero direction vector is possible (though useless), rotating around a zero axis vector makes no sense? So this commit adds an assert that the given axis is non-zero in `rotate_direction_around_axis`. And 'fixes' the found cases triggering such assert by skipping rotation when the axis (tangent) is null. Another related issue fixed by this commit is the iterative process in calls to `calculate_next_normal`, which can accumulate small floating point errors over time, leading to generating not normalized-enough normals at some point. Some questions: * Should we have an epsilon-based check for zero vector, instead of relying on 'exaclty zero' check? For tangents, since they are assumed normalized, it does not matter that much, but in general this may be a better option? Could not find any `is_almost_zero` helper though. * In the specific cases fixed here, is it best to skip rotation when the tangent is null, or should we rather try to use the previous tangent e.g.?
Bastien Montagne added the
Module
Modeling
label 2024-05-29 16:07:56 +02:00
Bastien Montagne requested review from Jacques Lucke 2024-05-29 16:08:32 +02:00
Bastien Montagne requested review from Simon Thommes 2024-05-29 16:08:33 +02:00
Bastien Montagne requested review from Hans Goudey 2024-05-29 16:08:33 +02:00
Author
Owner

@blender-bot build

@blender-bot build
Iliya Katushenock changed title from Fix (unreported) asserts in curve geometry code. to Fix #121169: asserts in curve geometry code. 2024-05-29 16:10:37 +02:00
Iliya Katushenock added this to the Nodes & Physics project 2024-05-29 16:11:09 +02:00
Iliya Katushenock added the
Interest
Geometry Nodes
label 2024-05-29 16:11:13 +02:00
Hans Goudey reviewed 2024-05-29 16:24:46 +02:00
Hans Goudey left a comment
Member

I think checking equality for 0 is fine, if it's not zero the values should be defined and normalized.

I think checking equality for 0 is fine, if it's not zero the values should be defined and normalized.
@ -198,1 +200,4 @@
for (const int i : normals.index_range()) {
const float3 axis = tangents[i];
if (math::is_zero(axis)) {
continue;
Member

This leaves normals[i] uninitialized, so we'll have to do slightly more than this. I'd advocate for doing the simplest thing though, since normals are undefined in these cases anyway. How about normals[i] = float3(0,0,1);. I'd also consider putting UNLIKELY in these checks.

This leaves `normals[i]` uninitialized, so we'll have to do slightly more than this. I'd advocate for doing the simplest thing though, since normals are undefined in these cases anyway. How about `normals[i] = float3(0,0,1);`. I'd also consider putting `UNLIKELY` in these checks.
Author
Owner

no it does not? AFAICT, this code adjusts already defined normals, so skipping should be fine (or at least, not 'too bad')? Since these situations should only happen in degenerate cases anyway.

Using UNLIKELY is a good point.

no it does not? AFAICT, this code _adjusts_ already defined normals, so skipping should be fine (or at least, not 'too bad')? Since these situations should only happen in degenerate cases anyway. Using `UNLIKELY` is a good point.
Member

Oh you're right, sorry I should have read this closer.

Oh you're right, sorry I should have read this closer.
Bastien Montagne force-pushed tmp-fix-curves-geometry-asserts from 0ab1e36ddb to d578b7e902 2024-05-29 16:41:20 +02:00 Compare
Bastien Montagne added 1 commit 2024-05-29 16:49:49 +02:00
Add (UN)LIKELY hints to vectors checks as suggested in review.
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
6797018c94
Author
Owner

@blender-bot build

@blender-bot build
Hans Goudey approved these changes 2024-05-29 17:33:37 +02:00
Author
Owner

I think checking equality for 0 is fine, if it's not zero the values should be defined and normalized.

My problem here is actually with the definition of BLI_ASSERT_UNIT_V3 and the like. I do not understand how an almost-null vector can be considered 'unit' vector?

But this goes beyond the scope of this bugfix PR, will create a new one with proposed changes.

> I think checking equality for 0 is fine, if it's not zero the values should be defined and normalized. My problem here is actually with the definition of `BLI_ASSERT_UNIT_V3` and the like. I do not understand how an almost-null vector can be considered 'unit' vector? But this goes beyond the scope of this bugfix PR, will create a new one with proposed changes.
Bastien Montagne merged commit e18dd894b8 into main 2024-05-30 10:24:19 +02:00
Bastien Montagne deleted branch tmp-fix-curves-geometry-asserts 2024-05-30 10:24:22 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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 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#122441
No description provided.