diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-02-13 14:35:33 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-02-13 14:35:33 +0300 |
commit | ae635771b2f9ebd94e2c3461362c0ed5a39ecce4 (patch) | |
tree | c3d47cc18975d95485b0387b0f31e27e9bfd54e3 | |
parent | 33fb3441714cd36e5550f7ebdae52e0d20023f2c (diff) |
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.
-rw-r--r-- | intern/cycles/util/util_guarded_allocator.h | 12 |
1 files 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 } |