ソースを参照

Merge pull request #3113 from thomasbiang/assimp_gltf2_exporter

Fix gltf2 exporter memory crash
Kim Kulling 5 年 前
コミット
210f40e984
1 ファイル変更10 行追加5 行削除
  1. 10 5
      code/glTF2/glTF2Asset.inl

+ 10 - 5
code/glTF2/glTF2Asset.inl

@@ -508,18 +508,23 @@ inline size_t Buffer::AppendData(uint8_t *data, size_t length) {
 }
 
 inline void Buffer::Grow(size_t amount) {
-    if (amount <= 0) return;
+    if (amount <= 0) {
+        return;
+    }
+    
+    // Capacity is big enough
     if (capacity >= byteLength + amount) {
         byteLength += amount;
         return;
     }
 
-    // Shift operation is standard way to divide integer by 2, it doesn't cast it to float back and forth, also works for odd numbers,
-    // originally it would look like: static_cast<size_t>(capacity * 1.5f)
-    capacity = std::max(capacity + (capacity >> 1), byteLength + amount);
+    // Just allocate data which we need
+    capacity = byteLength + amount;
 
     uint8_t *b = new uint8_t[capacity];
-    if (mData) memcpy(b, mData.get(), byteLength);
+    if (nullptr != mData) {
+        memcpy(b, mData.get(), byteLength);
+    }
     mData.reset(b, std::default_delete<uint8_t[]>());
     byteLength += amount;
 }