diff options
author | Richard Antalik <richardantalik@gmail.com> | 2021-01-10 18:50:08 +0300 |
---|---|---|
committer | Richard Antalik <richardantalik@gmail.com> | 2021-01-10 18:50:08 +0300 |
commit | e45630a99fc2cd7cfcf3c762ec9af32763a31dc2 (patch) | |
tree | e520d2a27e99ddb6bdbfec3d97b337f4b628bdf9 /source/blender/sequencer/intern/image_cache.c | |
parent | 9441413cb242f549ba1f86621ff72e90418313df (diff) |
Fix sequencer disk cache not writing data
Error handling added in 512a23c3d61d caused that reading header of new
file failed, since it is empty.
Don't attempt to read header if file is empty. If header can not be read
anyway, try to delete the file. Add asserts, as this should never
happen.
Reviewed By: sybren
Differential Revision: https://developer.blender.org/D9954
Diffstat (limited to 'source/blender/sequencer/intern/image_cache.c')
-rw-r--r-- | source/blender/sequencer/intern/image_cache.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/source/blender/sequencer/intern/image_cache.c b/source/blender/sequencer/intern/image_cache.c index a24fa4fe298..6818df6a986 100644 --- a/source/blender/sequencer/intern/image_cache.c +++ b/source/blender/sequencer/intern/image_cache.c @@ -518,6 +518,7 @@ static bool seq_disk_cache_read_header(FILE *file, DiskCacheHeader *header) fseek(file, 0, 0); const size_t num_items_read = fread(header, sizeof(*header), 1, file); if (num_items_read < 1) { + BLI_assert(!"unable to read disk cache header"); perror("unable to read disk cache header"); return false; } @@ -618,10 +619,14 @@ static bool seq_disk_cache_write_file(SeqDiskCache *disk_cache, SeqCacheKey *key seq_disk_cache_add_file_to_list(disk_cache, path); } + DiskCacheFile *cache_file = seq_disk_cache_get_file_entry_by_path(disk_cache, path); DiskCacheHeader header; memset(&header, 0, sizeof(header)); - if (!seq_disk_cache_read_header(file, &header)) { + /* BLI_make_existing_file() above may create an empty file. This is fine, don't atttempt reading + * the header in that case. */ + if (cache_file->fstat.st_size != 0 && !seq_disk_cache_read_header(file, &header)) { fclose(file); + seq_disk_cache_delete_file(disk_cache, cache_file); return false; } int entry_index = seq_disk_cache_add_header_entry(key, ibuf, &header); |