From e66f7011fb23e3509ad95accec581f6269813266 Mon Sep 17 00:00:00 2001 From: Mel Date: Wed, 26 Oct 2022 04:05:47 +0200 Subject: Fixed attribute double free --- src/GFX/Mesh.hpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/GFX') 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 Attribute( - std::vector> data - ) : data((T*) data.data()), - data_size(data.size()), + std::vector> 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; -- cgit 1.4.1