summary refs log tree commit diff
path: root/src/GFX
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-10-26 04:05:47 +0200
committerMel <einebeere@gmail.com>2022-10-26 04:05:47 +0200
commite66f7011fb23e3509ad95accec581f6269813266 (patch)
tree2535a617d10f76318dc4a3ae923258186fd9bac5 /src/GFX
parentdc2af6a6fb7ae3cf1b9f917058889329d4652491 (diff)
downloadmeowcraft-e66f7011fb23e3509ad95accec581f6269813266.tar.zst
meowcraft-e66f7011fb23e3509ad95accec581f6269813266.zip
Fixed attribute double free
Diffstat (limited to 'src/GFX')
-rw-r--r--src/GFX/Mesh.hpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/GFX/Mesh.hpp b/src/GFX/Mesh.hpp
index 9d640b6..36a7dac 100644
--- a/src/GFX/Mesh.hpp
+++ b/src/GFX/Mesh.hpp
@@ -12,11 +12,25 @@ public:
     struct Attribute {
         template<size_t S = 3, typename T = float>
         Attribute(
-            std::vector<Vector<S, T>> data
-        ) : data((T*) data.data()),
-            data_size(data.size()),
+            std::vector<Vector<S, T>> v
+        ) : data_size(v.size()),
             attribute_size(S),
-            type_size(sizeof(T)) {};
+            type_size(sizeof(T)) {
+            data = copy(v.data(), v.size() * S * type_size);
+        };
+
+        Attribute(
+            const Attribute& other
+        ) : data(copy(other.data, other.data_size * other.attribute_size * other.type_size)),
+            data_size(other.data_size),
+            attribute_size(other.attribute_size),
+            type_size(other.type_size) {};
+
+        static void* copy(void* ptr, uint32_t size) {
+            auto* buffer = new uint8_t[size];
+            std::copy((uint8_t*)ptr, (uint8_t*)ptr + size, buffer);
+            return buffer;
+        }
 
         void* data;
         long data_size;