Fix T84935: boolean custom data layers not saved correctly
The issue was that boolean custom data layers were not written to files, because the dna struct name `bool` does not exist. Adding a struct that just contains a `bool/uint8_t` does not seem to be possible, it looks like the minimum dna struct size is 4 bytes. The proposed solution has two parts: 1. Write the custom data layer using `BLO_write_raw` instead of `BLO_write_struct_array_by_name`. 2. When loading a file, reinitialize any custom data layer that was not saved correctly (this is just a fix for existing files). Differential Revision: https://developer.blender.org/D10194
This commit is contained in:
@@ -5104,6 +5104,10 @@ void CustomData_blend_write(BlendWriter *writer,
|
||||
const int *layer_data = layer->data;
|
||||
BLO_write_raw(writer, sizeof(*layer_data) * count, layer_data);
|
||||
}
|
||||
else if (layer->type == CD_PROP_BOOL) {
|
||||
const bool *layer_data = layer->data;
|
||||
BLO_write_raw(writer, sizeof(*layer_data) * count, layer_data);
|
||||
}
|
||||
else {
|
||||
const char *structname;
|
||||
int structnum;
|
||||
@@ -5193,6 +5197,16 @@ void CustomData_blend_read(BlendDataReader *reader, CustomData *data, int count)
|
||||
|
||||
if (CustomData_verify_versions(data, i)) {
|
||||
BLO_read_data_address(reader, &layer->data);
|
||||
if (layer->data == NULL) {
|
||||
/* Usually this should never happen, except when a custom data layer has not been written
|
||||
* to a file correctly. */
|
||||
CLOG_WARN(&LOG, "Reallocating custom data layer that was not saved correctly.");
|
||||
const LayerTypeInfo *info = layerType_getInfo(layer->type);
|
||||
layer->data = MEM_calloc_arrayN((size_t)count, info->size, layerType_getName(layer->type));
|
||||
if (info->set_default) {
|
||||
info->set_default(layer->data, count);
|
||||
}
|
||||
}
|
||||
if (layer->type == CD_MDISPS) {
|
||||
blend_read_mdisps(reader, count, layer->data, layer->flag & CD_FLAG_EXTERNAL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user