diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2015-09-04 10:38:10 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2015-10-11 17:41:59 +0300 |
commit | 34e7285b0a62e0a4daa74caecbaea2932b13c05b (patch) | |
tree | ff7db3d1aee1bf56296af63c74d06d2a5c16d8f9 /intern/cycles/util | |
parent | 27be9a2f3bdfc280a612b0d8137e473b2139ea76 (diff) |
Cycles: Gracefully handle out-of-memory happening in device vector
Currently only image loading benefits of this and will give magenta color
when image manager detects it's running out of memory.
This isn't ideal solution and can't handle all cases. For example, OOM
killer might kill process before it realized it run out of memory, but
in other cases this could prevent some crashes.
Reviewers: juicyfruit, dingto
Differential Revision: https://developer.blender.org/D1502
Diffstat (limited to 'intern/cycles/util')
-rw-r--r-- | intern/cycles/util/util_vector.h | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/intern/cycles/util/util_vector.h b/intern/cycles/util/util_vector.h index ee1f997721d..623436483a0 100644 --- a/intern/cycles/util/util_vector.h +++ b/intern/cycles/util/util_vector.h @@ -163,7 +163,7 @@ public: util_aligned_free(data); } - void resize(size_t newsize) + T* resize(size_t newsize) { if(newsize == 0) { clear(); @@ -171,7 +171,12 @@ public: else if(newsize != datasize) { if(newsize > capacity) { T *newdata = (T*)util_aligned_malloc(sizeof(T)*newsize, alignment); - if(data) { + if(newdata == NULL) { + /* Allocation failed, likely out of memory. */ + clear(); + return NULL; + } + else if(data) { memcpy(newdata, data, ((datasize < newsize)? datasize: newsize)*sizeof(T)); util_aligned_free(data); } @@ -180,12 +185,15 @@ public: } datasize = newsize; } + return data; } void clear() { - util_aligned_free(data); - data = NULL; + if(data != NULL) { + util_aligned_free(data); + data = NULL; + } datasize = 0; capacity = 0; } |