Fix #112068: Crash when loading converted curves #112280

Merged
Falk David merged 6 commits from filedescriptor/blender:fix-112068 into main 2023-09-12 16:02:12 +02:00
Member

In 2788fa915b the CurvesGeometry::blend_write and CurvesGeometry::blend_read functions were added. Unfortunately, the commit also altered the writing logic and introduced a bug where loading a file with a converted Curves object would crash. See #112068.

This PR fixes the issue by making sure that CustomData_blend_write_prepare is called before BKE_id_blend_write, which is the root cause of the crash that happens on load.

The CurvesGeometry::blend_write function is split into CurvesGeometry::blend_write_prepare and CurvesGeometry::blend_write.

In https://projects.blender.org/blender/blender/commit/2788fa915be6a7da0a0b0ad63626c095eef1e216 the `CurvesGeometry::blend_write` and `CurvesGeometry::blend_read` functions were added. Unfortunately, the commit also altered the writing logic and introduced a bug where loading a file with a converted `Curves` object would crash. See https://projects.blender.org/blender/blender/issues/112068. This PR fixes the issue by making sure that `CustomData_blend_write_prepare` is called before `BKE_id_blend_write`, which is the root cause of the crash that happens on load. The `CurvesGeometry::blend_write` function is split into `CurvesGeometry::blend_write_prepare` and `CurvesGeometry::blend_write`.
Falk David added 1 commit 2023-09-12 14:02:29 +02:00
Falk David requested review from Hans Goudey 2023-09-12 14:03:32 +02:00
Falk David requested review from Bastien Montagne 2023-09-12 14:03:42 +02:00
Hans Goudey approved these changes 2023-09-12 14:13:07 +02:00
Bastien Montagne requested changes 2023-09-12 14:24:47 +02:00
Bastien Montagne left a comment
Owner

There should be a proper technical explanation about this change in the commit message (what was the issue with current code, why/how this commit fixes it). This is not exactly trivial, especially since current Curves data layout 'embeds' two other sub-layers of data (so writing the root ID struct also implicitly writes the CurvesGeometry data, which writes the CustomData)...

On a general level, I would also rather have a single CurvesGeometryBlendWriteData blend_write_data variable, generated by a new CurvesGeometry::blend_write_prepare() method, and passed as single third extra argument to CurvesGeometry::blend_write() (would also keep the ID as second argument here btw).

That way, the logic is easier to extend in the future if needs be, and is not spread/duplicated in several parts of the code.

There should be a proper technical explanation about this change in the commit message (what was the issue with current code, why/how this commit fixes it). This is not exactly trivial, especially since current Curves data layout 'embeds' two other sub-layers of data (so writing the root ID struct also implicitly writes the `CurvesGeometry` data, which writes the `CustomData`)... On a general level, I would also rather have a single `CurvesGeometryBlendWriteData blend_write_data` variable, generated by a new `CurvesGeometry::blend_write_prepare()` method, and passed as single third extra argument to `CurvesGeometry::blend_write()` (would also keep the ID as second argument here btw). That way, the logic is easier to extend in the future if needs be, and is not spread/duplicated in several parts of the code.
Falk David added 1 commit 2023-09-12 14:42:46 +02:00
Falk David requested review from Bastien Montagne 2023-09-12 14:47:59 +02:00
Bastien Montagne approved these changes 2023-09-12 14:54:10 +02:00
Bastien Montagne left a comment
Owner

Generally LGTM now, would rather have actual C++ experts give it another pass though.

Left a couple of comments, but generally the structure of the new code looks good to me, so don't think another review would be necessary from me at this point.

Generally LGTM now, would rather have actual C++ experts give it another pass though. Left a couple of comments, but generally the structure of the new code looks good to me, so don't think another review would be necessary from me at this point.
@ -399,0 +409,4 @@
* This function needs to be called before `blend_write` and before the `CurvesGeometry` struct
* is written because it can mutate the `CustomData` struct.
*/
void blend_write_prepare(CurvesGeometryBlendWriteData &write_data);

Not a C++ expert, but can't this function simply return a CurvesGeometryBlendWriteData object? I would expect a copy elision to happen here (or at worse, a copy using the 'move' mechanism)?

Not a C++ expert, but can't this function simply return a `CurvesGeometryBlendWriteData` object? I would expect a copy elision to happen here (or at worse, a copy using the 'move' mechanism)?
filedescriptor marked this conversation as resolved
@ -399,0 +410,4 @@
* is written because it can mutate the `CustomData` struct.
*/
void blend_write_prepare(CurvesGeometryBlendWriteData &write_data);
void blend_write(BlendWriter &writer, const CurvesGeometryBlendWriteData &write_data ID &id);

missing coma?...

Also, please pass the ID argument first (just after the writer one), it remains the 'main' data to be written, additional data specific to a data types should be added after it.

missing coma?... Also, please pass the ID argument first (just after the `writer` one), it remains the 'main' data to be written, additional data specific to a data types should be added after it.
filedescriptor marked this conversation as resolved
Bastien Montagne requested review from Hans Goudey 2023-09-12 14:54:22 +02:00
Hans Goudey reviewed 2023-09-12 14:56:38 +02:00
@ -54,0 +54,4 @@
/**
* Helper struct for `CurvesGeometry::blend_write_*` functions.
*/
struct CurvesGeometryBlendWriteData {
Member

This struct could be defined as BlendWriteData just before the blend_write_prepare function, inside bke::CurvesGeometry

This struct could be defined as `BlendWriteData` just before the `blend_write_prepare` function, inside `bke::CurvesGeometry`
filedescriptor marked this conversation as resolved
Falk David added 1 commit 2023-09-12 15:15:05 +02:00
Hans Goudey requested changes 2023-09-12 15:24:31 +02:00
@ -394,3 +394,3 @@
* File Read/Write.
*/
public:
Member

Is public necessary here? Seems the stuff above is already public

Is public necessary here? Seems the stuff above is already public
filedescriptor marked this conversation as resolved
@ -105,12 +105,16 @@ static void curves_blend_write(BlendWriter *writer, ID *id, const void *id_addre
{
Curves *curves = (Curves *)id;
/* Make sure to call `CurvesGeometry::blend_write_prepare()` before writing the struct. */
Member

Think this comment is redundant with documentation in blend_write_prepare and the face that blend_write requires this as an argument. Same in the GP file

Think this comment is redundant with documentation in `blend_write_prepare` and the face that `blend_write` requires this as an argument. Same in the GP file
filedescriptor marked this conversation as resolved
Falk David added 2 commits 2023-09-12 15:38:12 +02:00
Hans Goudey approved these changes 2023-09-12 15:46:59 +02:00
@ -2054,3 +2055,4 @@
switch (drawing_base->type) {
case GP_DRAWING: {
GreasePencilDrawing *drawing = reinterpret_cast<GreasePencilDrawing *>(drawing_base);
blender::bke::CurvesGeometry::BlendWriteData write_data =
Member

blender:: unnecessary here

`blender::` unnecessary here
filedescriptor marked this conversation as resolved
Falk David added 1 commit 2023-09-12 16:01:39 +02:00
Falk David merged commit 97d2dbb24e into main 2023-09-12 16:02:12 +02:00
Falk David deleted branch fix-112068 2023-09-12 16:02:13 +02: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
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#112280
No description provided.