[Bf-blender-cvs] [e45630a99fc] master: Fix sequencer disk cache not writing data

Richard Antalik noreply at git.blender.org
Sun Jan 10 16:53:55 CET 2021


Commit: e45630a99fc2cd7cfcf3c762ec9af32763a31dc2
Author: Richard Antalik
Date:   Sun Jan 10 16:50:08 2021 +0100
Branches: master
https://developer.blender.org/rBe45630a99fc2cd7cfcf3c762ec9af32763a31dc2

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

===================================================================

M	source/blender/sequencer/intern/image_cache.c

===================================================================

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);



More information about the Bf-blender-cvs mailing list