Memory leak and design violation in curve evaluation #96498

Closed
opened 2022-03-15 17:45:42 +01:00 by Sergey Sharybin · 7 comments

System Information
Operating system: Linux-5.16.0-4-amd64-x86_64-with-glibc2.33 64 Bits
Graphics card: Quadro RTX 6000/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 510.54

Blender Version
Broken: version: 3.2.0 Alpha, branch: Unknown, commit date: Unknown Unknown, hash: rBUnknown
Worked: Prior to D11597 c946fdb2e5

Short description of error

Rendering on playing back lib/tests/render/motion_blur/multi_step_motion_blur.blend results in memory leak.

Exact steps for others to reproduce the error

Easiest to see if LSAN is enabled, but guarded allocator also catches the issue.

Way 1: Open the file, hit F12, observe memory leak printed on exit.
Way 2: Open the file, hit playback, exit

There are two things which on a glance seems to be wrong in the new implementation (since the mentioned patch) in the BKE_displist_make_curveTypes.

The ob->data at the moment of the function is called is not "localized" to the object: if multiple objects are sharing the same curve multiple copy-on-write objects will share the same copy-on-write curve. This means that writing to cow_curve.curve_eval is "illegal". The general rule: do not write to object-data level when evaluating object. This general rule is violated without either explanation or realization that it is something bad.

The freeing of Curve::curve_eval is only happening in the curve_free_data, which means evaluating same depsgraph at different times will not free this data: cow_curve.curve_eval = nullptr;.

P.S. The comment in the Curve::CurveEval states Owned by the object's #geometry_set_eval. That's the giveaway: something owned by object level can not be stored in the object-data level.

**System Information** Operating system: Linux-5.16.0-4-amd64-x86_64-with-glibc2.33 64 Bits Graphics card: Quadro RTX 6000/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 510.54 **Blender Version** Broken: version: 3.2.0 Alpha, branch: Unknown, commit date: Unknown Unknown, hash: `rBUnknown` Worked: Prior to [D11597](https://archive.blender.org/developer/D11597) c946fdb2e5 **Short description of error** Rendering on playing back `lib/tests/render/motion_blur/multi_step_motion_blur.blend` results in memory leak. **Exact steps for others to reproduce the error** Easiest to see if LSAN is enabled, but guarded allocator also catches the issue. Way 1: Open the file, hit F12, observe memory leak printed on exit. Way 2: Open the file, hit playback, exit There are two things which on a glance seems to be wrong in the new implementation (since the mentioned patch) in the `BKE_displist_make_curveTypes`. The `ob->data` at the moment of the function is called is not "localized" to the object: if multiple objects are sharing the same curve multiple copy-on-write objects will share the same copy-on-write curve. This means that writing to `cow_curve.curve_eval` is "illegal". The general rule: do not write to object-data level when evaluating object. This general rule is violated without either explanation or realization that it is something bad. The freeing of `Curve::curve_eval` is only happening in the `curve_free_data`, which means evaluating same depsgraph at different times will not free this data: `cow_curve.curve_eval = nullptr;`. P.S. The comment in the `Curve::CurveEval` states `Owned by the object's #geometry_set_eval`. That's the giveaway: something owned by object level can not be stored in the object-data level.
Author
Owner

Added subscriber: @Sergey

Added subscriber: @Sergey
Member

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

Changed status from 'Needs Triage' to: 'Confirmed'
Hans Goudey self-assigned this 2022-03-15 18:01:27 +01:00
Member

Yikes, I just realized the problem is worse than I expected. Even in 3.1, a modifier on a single curve object affects all users of the original curve. I'm amazed that behavior made it so long in master.
{F12929626 size=full}

I can relatively easily fix that problem by moving the final evaluated CurveEval around to a different place, but not yet without causing other problems. Maybe I'll have better luck tomorrow.

Really though, I'm thinking that the easiest/best way to fix this might be just using the new curves object for rendering. That's already planned for the next week or two anyway.

Yikes, I just realized the problem is worse than I expected. Even in 3.1, a modifier on a single curve object affects all users of the original curve. I'm amazed that behavior made it so long in master. {[F12929626](https://archive.blender.org/developer/F12929626/image.png) size=full} I can relatively easily fix that problem by moving the final evaluated `CurveEval` around to a different place, but not yet without causing other problems. Maybe I'll have better luck tomorrow. Really though, I'm thinking that the easiest/best way to fix this might be just using the new curves object for rendering. That's already planned for the next week or two anyway.
Author
Owner

I'm thinking that the easiest/best way to fix this might be just using the new curves object for rendering

Will this allow us to get rid of CurveEval from the Curve datablock?
Other thought to keep in mind: is this issue something we want to be fixed in possible upcoming corrective release for 3.1?

Other than that, focusing on the proper solution is surely better idea than trying to find a quicker and less ideal fix.

> I'm thinking that the easiest/best way to fix this might be just using the new curves object for rendering Will this allow us to get rid of `CurveEval` from the `Curve` datablock? Other thought to keep in mind: is this issue something we want to be fixed in possible upcoming corrective release for 3.1? Other than that, focusing on the proper solution is surely better idea than trying to find a quicker and less ideal fix.
Member

In #96498#1323899, @Sergey wrote:
Will this allow us to get rid of CurveEval from the Curve datablock?

Yes, it would, since Curve wouldn't be used for rendering at all. We would just need a way to draw the Curve edit mode overlays from the Curves data type, which sounds a bit weird, but maybe still better than alternatives.

Other thought to keep in mind: is this issue something we want to be fixed in possible upcoming corrective release for 3.1?

Hmm, I don't really think so, it's a bad bug but also a tenuous situation, not an area I'd change in a corrective release.

> In #96498#1323899, @Sergey wrote: > Will this allow us to get rid of `CurveEval` from the `Curve` datablock? Yes, it would, since `Curve` wouldn't be used for rendering at all. We would just need a way to draw the `Curve` edit mode overlays from the `Curves` data type, which sounds a bit weird, but maybe still better than alternatives. > Other thought to keep in mind: is this issue something we want to be fixed in possible upcoming corrective release for 3.1? Hmm, I don't really think so, it's a bad bug but also a tenuous situation, not an area I'd change in a corrective release.

This issue was referenced by a7c65ef4cb

This issue was referenced by a7c65ef4cbbd71972170cc8406a85b2332d304f2
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
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#96498
No description provided.