Core: Fix broken CustomData IO with Autosave files #106648

Merged
Joseph Eagar merged 5 commits from temp-autosave-bug into main 2023-04-07 02:02:31 +02:00
Member

Autosave files are created from memfile undo, which
doesn't save legacy mesh data. This leads to a crash
on file load.

In addition the mesh code can now add CustomData
layers when saving files, which did not work if
the original domain had no layers. In that case
CustomData.layers is NULL and DNA has nothing to
key off of when loading the file later.

Autosave files are created from memfile undo, which doesn't save legacy mesh data. This leads to a crash on file load. In addition the mesh code can now add CustomData layers when saving files, which did not work if the original domain had no layers. In that case CustomData.layers is NULL and DNA has nothing to key off of when loading the file later.
Joseph Eagar added 1 commit 2023-04-07 01:25:22 +02:00
182d83f281 Core: Fix broken CustomData IO with Autosave files
Autosave files are created from memfile undo, which
doesn't save legacy mesh data. This leads to a crash
on file load.

In addition the mesh code can now add CustomData
layers when saving files, which did not work if
the original domain had no layers.  In that case
CustomData.layers is NULL and DNA has nothing to
key off of when loading the file later.
Hans Goudey requested changes 2023-04-07 01:35:05 +02:00
@ -4220,0 +4220,4 @@
/* Note: data->layers may be null, this happens when adding
* a legacy MPoly struct to a mesh with no other face attributes.
* This leaves us with no unique ID for DNA to key off of when
Member

I wonder if there's a more specific wording than "key off of". What about something like "identify the old data with"?

I think my lack of understanding here is the key part of the problem.

I wonder if there's a more specific wording than "key off of". What about something like "identify the old data with"? I think my lack of understanding here is the key part of the problem.
@ -1243,6 +1243,7 @@ void BKE_mesh_legacy_sharp_faces_from_flags(Mesh *mesh)
if (attributes.contains("sharp_face")) {
return;
}
Member

Unnecessary white-space change here

Unnecessary white-space change here
@ -29,1 +36,4 @@
{
/* Autosave files don't have CD_MPOLY layers.
*/
if (!CustomData_has_layer(&mesh.pdata, CD_MPOLY) && mesh.poly_offset_indices) {
Member

It shouldn't be necessary to add this at runtime, since we don't use the polys at all. We're meant to be able to read the new (not legacy format) too already. Is this preventing another crash in some of the functions below?

It shouldn't be necessary to add this at runtime, since we don't use the polys at all. We're meant to be able to read the new (not legacy format) too already. Is this preventing another crash in some of the functions below?
Joseph Eagar added 1 commit 2023-04-07 01:40:41 +02:00
Joseph Eagar reviewed 2023-04-07 01:41:56 +02:00
@ -29,1 +36,4 @@
{
/* Autosave files don't have CD_MPOLY layers.
*/
if (!CustomData_has_layer(&mesh.pdata, CD_MPOLY) && mesh.poly_offset_indices) {
Author
Member

A fair number of the conversion functions are using MPolys (it crashes in the sharp face one).

A fair number of the conversion functions are using MPolys (it crashes in the sharp face one).
Joseph Eagar added 1 commit 2023-04-07 01:49:46 +02:00
Hans Goudey requested changes 2023-04-07 01:52:08 +02:00
@ -4220,0 +4225,4 @@
*/
if (!data.layers && layers_to_write.size() > 0) {
/* We just need an address that's unique. */
data.layers = reinterpret_cast<CustomDataLayer *>(&data.layers);
Member

Would using layers_to_write.data() here be a little less "weird"?

No strong opinion since this is a bit hacky anyway, but it would look less suspect anyway.

Would using `layers_to_write.data()` here be a little less "weird"? No strong opinion since this is a bit hacky anyway, but it would look less suspect anyway.
@ -8,21 +8,28 @@
#include "CLG_log.h"
#include "DNA_mesh_types.h"
Member

All these includes are unnecessary now :)

All these includes are unnecessary now :)
Joseph Eagar added 1 commit 2023-04-07 01:52:57 +02:00
Joseph Eagar added 1 commit 2023-04-07 01:54:03 +02:00
Joseph Eagar reviewed 2023-04-07 01:59:31 +02:00
@ -4220,0 +4225,4 @@
*/
if (!data.layers && layers_to_write.size() > 0) {
/* We just need an address that's unique. */
data.layers = reinterpret_cast<CustomDataLayer *>(&data.layers);
Author
Member

There's no guarantee it will always be unique.

There's no guarantee it will always be unique.
Hans Goudey approved these changes 2023-04-07 02:01:45 +02:00
Hans Goudey left a comment
Member

Thank you very much!

Thank you very much!
@ -4220,0 +4225,4 @@
*/
if (!data.layers && layers_to_write.size() > 0) {
/* We just need an address that's unique. */
data.layers = reinterpret_cast<CustomDataLayer *>(&data.layers);
Member

Ah right, this is the best way to get an actually unique pointer I guess.

Ah right, this is the best way to get an actually unique pointer I guess.
Joseph Eagar merged commit dc71530d9c into main 2023-04-07 02:02:31 +02:00
Joseph Eagar deleted branch temp-autosave-bug 2023-04-07 02:02:32 +02:00
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#106648
No description provided.