1
1

Cleanup: blendloader: add logger to writefile.c, remove some asserts.

Properly use CLOG to report info or errors in `writefile.c`, instead of
printf's.

And remove some assert when logging error reports and the issue is not
critical.
This commit is contained in:
2022-05-17 15:29:24 +02:00
parent b759a3eac0
commit 939c2387a1
2 changed files with 20 additions and 13 deletions

View File

@@ -477,7 +477,6 @@ static void split_libdata(ListBase *lb_src, Main **lib_main_array, const uint li
}
else {
CLOG_ERROR(&LOG, "Invalid library for '%s'", id->name);
BLI_assert(0);
}
}
}

View File

@@ -73,6 +73,8 @@
#include "BLI_utildefines.h"
#include "CLG_log.h"
/* allow writefile to use deprecated functionality (for forward compatibility code) */
#define DNA_DEPRECATED_ALLOW
@@ -133,6 +135,8 @@
#define ZSTD_COMPRESSION_LEVEL 3
static CLG_LogRef LOG = {"blo.writefile"};
/** Use if we want to store how many bytes have been written to the file. */
// #define USE_WRITE_DATA_LEN
@@ -973,7 +977,7 @@ static void write_libraries(WriteData *wd, Main *main)
if (main->curlib->packedfile) {
BKE_packedfile_blend_write(&writer, main->curlib->packedfile);
if (wd->use_memfile == false) {
printf("write packed .blend: %s\n", main->curlib->filepath);
CLOG_INFO(&LOG, 2, "Write packed .blend: %s\n", main->curlib->filepath);
}
}
@@ -984,12 +988,11 @@ static void write_libraries(WriteData *wd, Main *main)
((id->tag & LIB_TAG_EXTERN) ||
((id->tag & LIB_TAG_INDIRECT) && (id->flag & LIB_INDIRECT_WEAK_LINK)))) {
if (!BKE_idtype_idcode_is_linkable(GS(id->name))) {
printf(
"ERROR: write file: data-block '%s' from lib '%s' is not linkable "
"but is flagged as directly linked\n",
id->name,
main->curlib->filepath_abs);
BLI_assert(0);
CLOG_ERROR(&LOG,
"Data-block '%s' from lib '%s' is not linkable, but is flagged as "
"directly linked\n",
id->name,
main->curlib->filepath_abs);
}
writestruct(wd, ID_LINK_PLACEHOLDER, ID, 1, id);
}
@@ -1129,9 +1132,15 @@ static bool write_file_handle(Main *mainvar,
char id_buffer_static[ID_BUFFER_STATIC_SIZE];
void *id_buffer = id_buffer_static;
const size_t idtype_struct_size = BKE_idtype_get_info_from_id(id)->struct_size;
const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id);
const size_t idtype_struct_size = id_type->struct_size;
if (idtype_struct_size > ID_BUFFER_STATIC_SIZE) {
BLI_assert(0);
CLOG_ERROR(&LOG,
"ID maximum buffer size (%d bytes) is not big enough to fit IDs of type %s, "
"which needs %lu bytes",
ID_BUFFER_STATIC_SIZE,
id_type->name,
id_type->struct_size);
id_buffer = MEM_mallocN(idtype_struct_size, __func__);
}
@@ -1200,7 +1209,6 @@ static bool write_file_handle(Main *mainvar,
* #direct_link_id_common in `readfile.c` anyway, */
((ID *)id_buffer)->py_instance = NULL;
const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id);
if (id_type->blend_write != NULL) {
id_type->blend_write(&writer, (ID *)id_buffer, id);
}
@@ -1482,7 +1490,7 @@ void BLO_write_struct_array_by_name(BlendWriter *writer,
{
int struct_id = BLO_get_struct_id_by_name(writer, struct_name);
if (UNLIKELY(struct_id == -1)) {
printf("error: can't find SDNA code <%s>\n", struct_name);
CLOG_ERROR(&LOG, "Can't find SDNA code <%s>\n", struct_name);
return;
}
BLO_write_struct_array_by_id(writer, struct_id, array_size, data_ptr);
@@ -1530,7 +1538,7 @@ void BLO_write_struct_list_by_name(BlendWriter *writer, const char *struct_name,
{
int struct_id = BLO_get_struct_id_by_name(writer, struct_name);
if (UNLIKELY(struct_id == -1)) {
printf("error: can't find SDNA code <%s>\n", struct_name);
CLOG_ERROR(&LOG, "Can't find SDNA code <%s>\n", struct_name);
return;
}
BLO_write_struct_list_by_id(writer, struct_id, list);