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
2 changed files with 11 additions and 1 deletions

View File

@ -4217,6 +4217,16 @@ void CustomData_blend_write_prepare(CustomData &data,
}
data.totlayer = layers_to_write.size();
data.maxlayer = data.totlayer;
/* 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 identify the old

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.
* data with when loading the file.
*/
if (!data.layers && layers_to_write.size() > 0) {
/* We just need an address that's unique. */
data.layers = reinterpret_cast<CustomDataLayer *>(&data.layers);
Review

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.
Review

There's no guarantee it will always be unique.

There's no guarantee it will always be unique.
Review

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.
}
}
int CustomData_sizeof(const eCustomDataType type)

View File

@ -1240,7 +1240,7 @@ void BKE_mesh_legacy_sharp_faces_from_flags(Mesh *mesh)
using namespace blender;
using namespace blender::bke;
MutableAttributeAccessor attributes = mesh->attributes_for_write();
if (attributes.contains("sharp_face")) {
if (attributes.contains("sharp_face") || !CustomData_get_layer(&mesh->pdata, CD_MPOLY)) {
return;
}
const Span<MPoly> polys(static_cast<const MPoly *>(CustomData_get_layer(&mesh->pdata, CD_MPOLY)),

Unnecessary white-space change here

Unnecessary white-space change here