[Bf-blender-cvs] [ae63577] master: Cycles: Fix crash caused by the guarded allocation commit

Sergey Sharybin noreply at git.blender.org
Sat Feb 13 12:37:58 CET 2016


Commit: ae635771b2f9ebd94e2c3461362c0ed5a39ecce4
Author: Sergey Sharybin
Date:   Sat Feb 13 12:35:33 2016 +0100
Branches: master
https://developer.blender.org/rBae635771b2f9ebd94e2c3461362c0ed5a39ecce4

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.

===================================================================

M	intern/cycles/util/util_guarded_allocator.h

===================================================================

diff --git a/intern/cycles/util/util_guarded_allocator.h b/intern/cycles/util/util_guarded_allocator.h
index 2cef149..91345e2 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
 	}




More information about the Bf-blender-cvs mailing list