From f2f107572cc3c2061b535e46f6a0d3571c555957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Fri, 26 Aug 2016 14:21:06 +0200 Subject: [PATCH] Fix T49168: crash when evaluating a cache constraint with a NULL cache file. --- source/blender/blenkernel/intern/constraint.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 70fdd4aa72e..116c75721af 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -4353,11 +4353,15 @@ static void transformcache_evaluate(bConstraint *con, bConstraintOb *cob, ListBa bTransformCacheConstraint *data = con->data; Scene *scene = cob->scene; - const float frame = BKE_scene_frame_get(scene); - const float time = BKE_cachefile_time_offset(data->cache_file, frame, FPS); - CacheFile *cache_file = data->cache_file; + if (!cache_file) { + return; + } + + const float frame = BKE_scene_frame_get(scene); + const float time = BKE_cachefile_time_offset(cache_file, frame, FPS); + BKE_cachefile_ensure_handle(G.main, cache_file); ABC_get_transform(cache_file->handle, cob->ob, data->object_path, @@ -4391,6 +4395,13 @@ static void transformcache_free(bConstraint *con) } } +static void transformcache_new_data(void *cdata) +{ + bTransformCacheConstraint *data = (bTransformCacheConstraint *)cdata; + + data->cache_file = NULL; +} + static bConstraintTypeInfo CTI_TRANSFORM_CACHE = { CONSTRAINT_TYPE_TRANSFORM_CACHE, /* type */ sizeof(bTransformCacheConstraint), /* size */ @@ -4399,7 +4410,7 @@ static bConstraintTypeInfo CTI_TRANSFORM_CACHE = { transformcache_free, /* free data */ transformcache_id_looper, /* id looper */ transformcache_copy, /* copy data */ - NULL, /* new data */ + transformcache_new_data, /* new data */ NULL, /* get constraint targets */ NULL, /* flush constraint targets */ NULL, /* get target matrix */