Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-01-26 14:02:02 +0300
committerJacques Lucke <jacques@blender.org>2021-01-26 14:05:40 +0300
commitdc8b31af578bfcf9f77dbce6d7b7da1006a3c8c1 (patch)
tree904c9179722b5aa5da5061c30a95b8e6d52185e3 /source/blender/blenkernel/intern/customdata.c
parent548d8a397c39f43459af404170614db6a18ebde1 (diff)
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
Diffstat (limited to 'source/blender/blenkernel/intern/customdata.c')
-rw-r--r--source/blender/blenkernel/intern/customdata.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 5d61b1165ed..446ef12574d 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -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);
}