From bba80ed7afa8ccea14310f35f767749f5d04207e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 17 Aug 2014 12:18:40 +1000 Subject: Cleanup --- intern/cycles/util/util_cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'intern/cycles/util/util_cache.h') diff --git a/intern/cycles/util/util_cache.h b/intern/cycles/util/util_cache.h index 417f4a869b6..c6752d942f1 100644 --- a/intern/cycles/util/util_cache.h +++ b/intern/cycles/util/util_cache.h @@ -25,7 +25,7 @@ * again into the appropriate data structures. * * This way we do not need to accurately track changes, compare dates and - * invalidate cache entries, at the cost of exta computation. If everything + * invalidate cache entries, at the cost of extra computation. If everything * is stored in a global cache, computations can perhaps even be shared between * different scenes where it may be hard to detect duplicate work. */ -- cgit v1.2.3 From 6212b7302cce8f6e2b5f9a0297b9595cf2ad69a8 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 1 Sep 2014 18:03:03 +0600 Subject: Cycles: Rebuild BVH from scratch if loading cache failed Before this Cycles used to try using the cache even so it knew for the fact that reading it from the disk failed. This change doesn't make it more stable if someone will try to trick Cycles and give malformed data but it solves general cases when Blender crashed during the cache write and will preserve rendering from crashing when trying to use that partial cache. --- intern/cycles/util/util_cache.h | 42 ++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'intern/cycles/util/util_cache.h') diff --git a/intern/cycles/util/util_cache.h b/intern/cycles/util/util_cache.h index c6752d942f1..bfb2877a22b 100644 --- a/intern/cycles/util/util_cache.h +++ b/intern/cycles/util/util_cache.h @@ -96,54 +96,70 @@ public: buffers.push_back(buffer); } - template void read(array& data) + template bool read(array& data) { size_t size; if(!fread(&size, sizeof(size), 1, f)) { fprintf(stderr, "Failed to read vector size from cache.\n"); - return; + return false; } if(!size) - return; + return false; data.resize(size/sizeof(T)); if(!fread(&data[0], size, 1, f)) { fprintf(stderr, "Failed to read vector data from cache (%lu).\n", (unsigned long)size); - return; + return false; } + return true; } - void read(int& data) + bool read(int& data) { size_t size; - if(!fread(&size, sizeof(size), 1, f)) + if(!fread(&size, sizeof(size), 1, f)) { fprintf(stderr, "Failed to read int size from cache.\n"); - if(!fread(&data, sizeof(data), 1, f)) + return false; + } + if(!fread(&data, sizeof(data), 1, f)) { fprintf(stderr, "Failed to read int from cache.\n"); + return false; + } + return true; } - void read(float& data) + bool read(float& data) { size_t size; - if(!fread(&size, sizeof(size), 1, f)) + if(!fread(&size, sizeof(size), 1, f)) { fprintf(stderr, "Failed to read float size from cache.\n"); - if(!fread(&data, sizeof(data), 1, f)) + return false; + } + if(!fread(&data, sizeof(data), 1, f)) { fprintf(stderr, "Failed to read float from cache.\n"); + return false; + } + return true; } - void read(size_t& data) + bool read(size_t& data) { size_t size; - if(!fread(&size, sizeof(size), 1, f)) + if(!fread(&size, sizeof(size), 1, f)) { fprintf(stderr, "Failed to read size_t size from cache.\n"); - if(!fread(&data, sizeof(data), 1, f)) + return false; + } + if(!fread(&data, sizeof(data), 1, f)) { fprintf(stderr, "Failed to read size_t from cache.\n"); + return false; + } + return true; } }; -- cgit v1.2.3