From ae635771b2f9ebd94e2c3461362c0ed5a39ecce4 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sat, 13 Feb 2016 12:35:33 +0100 Subject: [PATCH] Cycles: Fix crash caused by the guarded allocation commit C++ requires specific alignment of the allocations which was not an issue when using GCC but uncovered issue when using Clang on OSX. Perhaps some versions of Clang might show errors on other platforms as well. --- intern/cycles/util/util_guarded_allocator.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/intern/cycles/util/util_guarded_allocator.h b/intern/cycles/util/util_guarded_allocator.h index 2cef1494369..91345e2b74b 100644 --- a/intern/cycles/util/util_guarded_allocator.h +++ b/intern/cycles/util/util_guarded_allocator.h @@ -50,15 +50,21 @@ public: T *allocate(size_t n, const void *hint = 0) { - util_guarded_mem_alloc(n * sizeof(T)); + size_t size = n * sizeof(T); + util_guarded_mem_alloc(size); (void)hint; #ifdef WITH_BLENDER_GUARDEDALLOC if(n == 0) { return NULL; } - return (T*)MEM_mallocN(n * sizeof(T), "Cycles Alloc"); + /* C++ standard requires allocation functions to allocate memory suitably + * aligned for any standard type. This is 16 bytes for 64 bit platform as + * far as i concerned. We might over-align on 32bit here, but that should + * be all safe actually. + */ + return (T*)MEM_mallocN_aligned(size, 16, "Cycles Alloc"); #else - return (T*)malloc(n * sizeof(T)); + return (T*)malloc(size); #endif }