diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2014-12-19 14:49:27 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2014-12-19 15:34:50 +0300 |
commit | 3e0ff35b4b1bc9151206b250740031baea0f9204 (patch) | |
tree | 3b07df825598ea1874ccd45805b8a166f5fff5b5 /source/blender/blenkernel | |
parent | ef5c036d1c675ff9912ca321339a45c2ab923da9 (diff) |
Fix for bad file name string matching in point caches, leading to
deletion of baked caches.
This happens when objects use file names with matching prefixes:
"CubeX" -> not baked
"CubeXYZ" -> baked
The first objects cache should be discarded up to the current frame on
file load, but the second should be left intact. But because the cache
file names for both use the same prefix as well (based on hex name
representation) they both match the "CubeX" name and get discarded.
Adding the underscore terminator solves this issue, because it is never
part of the hex file name string.
WARNING: this solution does not work with custom names for point caches.
This feature is pretty much broken, users have to ensure their names
are unique themselves. Due to the possibility of underscores in names
and the ambiguity of point cache suffixes there is no reliable way to
encode filenames in that case.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/pointcache.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index b1d247a3d2c..19ed49c727a 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -2571,12 +2571,19 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra) if (pid->cache->flag & PTCACHE_DISK_CACHE) { ptcache_path(pid, path); - len = ptcache_filename(pid, filename, cfra, 0, 0); /* no path */ - dir = opendir(path); if (dir==NULL) return; - + + len = ptcache_filename(pid, filename, cfra, 0, 0); /* no path */ + /* append underscore terminator to ensure we don't match similar names + * from objects whose names start with the same prefix + */ + if (len < sizeof(filename) - 2) { + BLI_strncpy(filename + len, "_", sizeof(filename) - 2 - len); + len += 1; + } + BLI_snprintf(ext, sizeof(ext), "_%02u"PTCACHE_EXT, pid->stack_index); while ((de = readdir(dir)) != NULL) { |