From af55547766a2be8888344855087a919de43677a6 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Fri, 25 Mar 2016 11:46:24 -0700 Subject: [PATCH] Copy material schema buffers as new ref --- libraries/model/src/model/Material.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/libraries/model/src/model/Material.cpp b/libraries/model/src/model/Material.cpp index 5260143a7f..802650df93 100755 --- a/libraries/model/src/model/Material.cpp +++ b/libraries/model/src/model/Material.cpp @@ -18,26 +18,34 @@ using namespace gpu; Material::Material() : _key(0), _schemaBuffer(), - _textureMaps() { - - // only if created from nothing shall we create the Buffer to store the properties - Schema schema; - _schemaBuffer = gpu::BufferView(std::make_shared(sizeof(Schema), (const gpu::Byte*) &schema)); + _textureMaps() +{ + // created from nothing: create the Buffer to store the properties + Schema schema; + _schemaBuffer = gpu::BufferView(std::make_shared(sizeof(Schema), (const gpu::Byte*) &schema)); } Material::Material(const Material& material) : _key(material._key), - _schemaBuffer(material._schemaBuffer), - _textureMaps(material._textureMaps) { + _textureMaps(material._textureMaps) +{ + // copied: create the Buffer to store the properties, avoid holding a ref to the old Buffer + Schema schema; + _schemaBuffer = gpu::BufferView(std::make_shared(sizeof(Schema), (const gpu::Byte*) &schema)); + _schemaBuffer.edit() = material._schemaBuffer.get(); } Material& Material::operator= (const Material& material) { _key = (material._key); - _schemaBuffer = (material._schemaBuffer); _textureMaps = (material._textureMaps); + // copied: create the Buffer to store the properties, avoid holding a ref to the old Buffer + Schema schema; + _schemaBuffer = gpu::BufferView(std::make_shared(sizeof(Schema), (const gpu::Byte*) &schema)); + _schemaBuffer.edit() = material._schemaBuffer.get(); + return (*this); }