[Bf-blender-cvs] [aa766993939] temp-chunk-list: progress

Jacques Lucke noreply at git.blender.org
Sat Sep 10 13:27:16 CEST 2022


Commit: aa7669939390cd1c72e5a25f9b16e935e0263f2a
Author: Jacques Lucke
Date:   Sat Sep 10 12:59:51 2022 +0200
Branches: temp-chunk-list
https://developer.blender.org/rBaa7669939390cd1c72e5a25f9b16e935e0263f2a

progress

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

M	source/blender/blenlib/BLI_chunk_list.hh

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

diff --git a/source/blender/blenlib/BLI_chunk_list.hh b/source/blender/blenlib/BLI_chunk_list.hh
index 321bb4c7d0a..7d4f216d007 100644
--- a/source/blender/blenlib/BLI_chunk_list.hh
+++ b/source/blender/blenlib/BLI_chunk_list.hh
@@ -224,7 +224,13 @@ class ChunkList {
   {
     this->ensure_space_for_one();
     BLI_assert(active_end_ < active_capacity_end_);
-    new (active_end_) T(std::forward<Args>(args)...);
+    try {
+      new (active_end_) T(std::forward<Args>(args)...);
+    }
+    catch (...) {
+      this->move_end_back_to_prev_element();
+      throw;
+    }
     active_end_++;
   }
 
@@ -261,15 +267,20 @@ class ChunkList {
     T value = std::move(*(active_end_ - 1));
     active_end_--;
     std::destroy_at(active_end_);
+    this->move_end_back_to_prev_element();
+    return value;
+  }
 
+  void move_end_back_to_prev_element()
+  {
     if (active_end_ > active_begin_) {
-      return value;
+      return;
     }
     if (alloc_info_ == nullptr) {
-      return value;
+      return;
     }
     if (alloc_info_->active_chunk == 0) {
-      return value;
+      return;
     }
     RawChunk &old_chunk = alloc_info_->raw_chunks[alloc_info_->active_chunk];
     old_chunk.end_if_inactive = active_end_;
@@ -286,7 +297,6 @@ class ChunkList {
     active_begin_ = new_chunk.begin;
     active_end_ = new_chunk.end_if_inactive;
     active_capacity_end_ = new_chunk.capacity_end;
-    return value;
   }
 
   class Iterator {



More information about the Bf-blender-cvs mailing list