diff --git a/intern/cycles/util/util_stack_allocator.h b/intern/cycles/util/util_stack_allocator.h index 1acd2b18bc7..d7aab5b250c 100644 --- a/intern/cycles/util/util_stack_allocator.h +++ b/intern/cycles/util/util_stack_allocator.h @@ -40,14 +40,17 @@ public: /* Allocator construction/destruction. */ StackAllocator() - : pointer_(0) {} + : pointer_(0), + use_stack_(true) {} StackAllocator(const StackAllocator&) - : pointer_(0) {} + : pointer_(0), + use_stack_(true) {} template StackAllocator(const StackAllocator&) - : pointer_(0) {} + : pointer_(0), + use_stack_(false) {} /* Memory allocation/deallocation. */ @@ -57,7 +60,7 @@ public: if(n == 0) { return NULL; } - if(pointer_ + n >= SIZE) { + if(pointer_ + n >= SIZE || use_stack_ == false) { size_t size = n * sizeof(T); util_guarded_mem_alloc(size); T *mem; @@ -69,6 +72,7 @@ public: if(mem == NULL) { throw std::bad_alloc(); } + return mem; } T *mem = &data_[pointer_]; pointer_ += n; @@ -157,6 +161,7 @@ public: private: int pointer_; + bool use_stack_; T data_[SIZE]; };