diff --git a/tiny_bvh.h b/tiny_bvh.h index 62f000a..ec0d624 100644 --- a/tiny_bvh.h +++ b/tiny_bvh.h @@ -91,6 +91,8 @@ THE SOFTWARE. #define ALIGNED( x ) __declspec( align( x ) ) #define ALIGNED_MALLOC( x ) ( ( x ) == 0 ? 0 : _aligned_malloc( ( x ), 64 ) ) #define ALIGNED_FREE( x ) _aligned_free( x ) +#define OPERATOR_NEW_ALIGN(x) +#define OPERATOR_DELETE_ALIGN(x) #else // gcc / clang #include @@ -106,6 +108,8 @@ THE SOFTWARE. #define ALIGNED_MALLOC( x ) ( ( x ) == 0 ? 0 : aligned_alloc( 64, ( x ) ) ) #define ALIGNED_FREE( x ) free( x ) #endif +#define OPERATOR_NEW_ALIGN(x) (std::align_val_t(x)) +#define OPERATOR_DELETE_ALIGN(x) ,(std::align_val_t(x)) #endif // generic #ifdef BVH_USEAVX @@ -335,7 +339,7 @@ class BVH { ALIGNED_FREE( bvhNode ); delete[] triIdx; - delete[] fragment; + operator delete[](fragment OPERATOR_DELETE_ALIGN(32)); bvhNode = 0, triIdx = 0, fragment = 0; } float SAHCost( const unsigned int nodeIdx = 0 ) const @@ -1012,7 +1016,7 @@ void BVH::BuildAVX( const bvhvec4* vertices, const unsigned int primCount ) triIdx = new unsigned int[triCount]; bvhNode = (BVHNode*)ALIGNED_MALLOC( triCount * 2 * sizeof( BVHNode ) ); memset( &bvhNode[1], 0, 32 ); // avoid crash in refit. - fragment = new Fragment[triCount]; + fragment = new OPERATOR_NEW_ALIGN(32) Fragment[triCount]; idxCount = triCount; } else assert( triCount == primCount ); // don't change triangle count between builds. @@ -1433,4 +1437,4 @@ int BVH::Intersect_AltSoA( Ray& ray ) const #endif // TINYBVH_IMPLEMENTATION -#endif // TINY_BVH_H_ \ No newline at end of file +#endif // TINY_BVH_H_