diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-04-20 16:49:52 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-04-20 16:49:52 +0300 |
commit | e3544c9e28eded2403613d2bc5af8992c3aa734a (patch) | |
tree | 279c281d35d3b5c3c81a1e1c9b4469c3700b124f /intern/cycles/util/util_vector.h | |
parent | d7e4f920fd93a4ae5679e0eb6b228a349ab3b082 (diff) |
Cycles: Throw bad_alloc exception when custom allocators failed to allocate memory
This mimics behavior of default allocators in STL and allows all the routines
to catch out-of-memory exceptions and hopefully recover from that situation/
Diffstat (limited to 'intern/cycles/util/util_vector.h')
-rw-r--r-- | intern/cycles/util/util_vector.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/intern/cycles/util/util_vector.h b/intern/cycles/util/util_vector.h index 4eb0dde8308..ad579da2d2e 100644 --- a/intern/cycles/util/util_vector.h +++ b/intern/cycles/util/util_vector.h @@ -218,10 +218,16 @@ public: protected: inline T* mem_allocate(size_t N) { + if(N == 0) { + return NULL; + } T *mem = (T*)util_aligned_malloc(sizeof(T)*N, alignment); if(mem != NULL) { util_guarded_mem_alloc(sizeof(T)*N); } + else { + throw std::bad_alloc(); + } return mem; } |