From bed20692a6e6ba1d822f2a98b04113a26308b4b1 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 3 Sep 2013 13:57:32 +0200 Subject: [PATCH] Fixed OnResourceDestroy callback not called by the destructor Former-commit-id: 8b961101f88343ddd3bb382d2c333052efb03164 --- include/Nazara/Renderer/Material.hpp | 2 +- include/Nazara/Utility/IndexBuffer.hpp | 2 +- include/Nazara/Utility/VertexBuffer.hpp | 2 +- include/Nazara/Utility/VertexDeclaration.hpp | 2 +- src/Nazara/Renderer/Material.cpp | 5 +++++ src/Nazara/Utility/IndexBuffer.cpp | 5 +++++ src/Nazara/Utility/SkeletalMesh.cpp | 2 ++ src/Nazara/Utility/StaticMesh.cpp | 14 ++++++++------ src/Nazara/Utility/VertexBuffer.cpp | 5 +++++ src/Nazara/Utility/VertexDeclaration.cpp | 5 +++++ 10 files changed, 34 insertions(+), 10 deletions(-) diff --git a/include/Nazara/Renderer/Material.hpp b/include/Nazara/Renderer/Material.hpp index 318b36312..f7c1eca29 100644 --- a/include/Nazara/Renderer/Material.hpp +++ b/include/Nazara/Renderer/Material.hpp @@ -46,7 +46,7 @@ class NAZARA_API NzMaterial : public NzResource NzMaterial(); NzMaterial(const NzMaterial& material); NzMaterial(NzMaterial&& material); - ~NzMaterial() = default; + ~NzMaterial(); void Apply(const NzShaderProgram* program) const; diff --git a/include/Nazara/Utility/IndexBuffer.hpp b/include/Nazara/Utility/IndexBuffer.hpp index 0c788049d..35e069387 100644 --- a/include/Nazara/Utility/IndexBuffer.hpp +++ b/include/Nazara/Utility/IndexBuffer.hpp @@ -25,7 +25,7 @@ class NAZARA_API NzIndexBuffer : public NzResource NzIndexBuffer(bool largeIndices, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static); NzIndexBuffer(const NzIndexBuffer& indexBuffer); NzIndexBuffer(NzIndexBuffer&& indexBuffer) noexcept; - ~NzIndexBuffer() = default; + ~NzIndexBuffer(); unsigned int ComputeCacheMissCount() const; diff --git a/include/Nazara/Utility/VertexBuffer.hpp b/include/Nazara/Utility/VertexBuffer.hpp index 741504ae4..898c3f46f 100644 --- a/include/Nazara/Utility/VertexBuffer.hpp +++ b/include/Nazara/Utility/VertexBuffer.hpp @@ -26,7 +26,7 @@ class NAZARA_API NzVertexBuffer : public NzResource NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static); NzVertexBuffer(const NzVertexBuffer& vertexBuffer); NzVertexBuffer(NzVertexBuffer&& vertexBuffer) noexcept; - ~NzVertexBuffer() = default; + ~NzVertexBuffer(); bool Fill(const void* data, unsigned int startVertex, unsigned int length, bool forceDiscard = false); bool FillRaw(const void* data, unsigned int offset, unsigned int size, bool forceDiscard = false); diff --git a/include/Nazara/Utility/VertexDeclaration.hpp b/include/Nazara/Utility/VertexDeclaration.hpp index 1d39c1ab3..e9563f9d5 100644 --- a/include/Nazara/Utility/VertexDeclaration.hpp +++ b/include/Nazara/Utility/VertexDeclaration.hpp @@ -26,7 +26,7 @@ class NAZARA_API NzVertexDeclaration : public NzResource public: NzVertexDeclaration(); NzVertexDeclaration(NzVertexDeclaration& declaration); - ~NzVertexDeclaration() = default; + ~NzVertexDeclaration(); void DisableAttribute(nzAttributeUsage usage); void EnableAttribute(nzAttributeUsage usage, nzAttributeType type, unsigned int offset); diff --git a/src/Nazara/Renderer/Material.cpp b/src/Nazara/Renderer/Material.cpp index 77e1b9a11..c3c39a2b3 100644 --- a/src/Nazara/Renderer/Material.cpp +++ b/src/Nazara/Renderer/Material.cpp @@ -43,6 +43,11 @@ NzMaterial::NzMaterial(NzMaterial&& material) unit.program.Reset(); } +NzMaterial::~NzMaterial() +{ + NotifyDestroy(); +} + void NzMaterial::Apply(const NzShaderProgram* program) const { int alphaThresholdLocation = program->GetUniformLocation(nzShaderUniform_MaterialAlphaThreshold); diff --git a/src/Nazara/Utility/IndexBuffer.cpp b/src/Nazara/Utility/IndexBuffer.cpp index 92f4b8e64..21459206c 100644 --- a/src/Nazara/Utility/IndexBuffer.cpp +++ b/src/Nazara/Utility/IndexBuffer.cpp @@ -41,6 +41,11 @@ m_startOffset(indexBuffer.m_startOffset) { } +NzIndexBuffer::~NzIndexBuffer() +{ + NotifyDestroy(); +} + unsigned int NzIndexBuffer::ComputeCacheMissCount() const { NzIndexMapper mapper(this); diff --git a/src/Nazara/Utility/SkeletalMesh.cpp b/src/Nazara/Utility/SkeletalMesh.cpp index b4d14e782..eea9680d9 100644 --- a/src/Nazara/Utility/SkeletalMesh.cpp +++ b/src/Nazara/Utility/SkeletalMesh.cpp @@ -182,6 +182,8 @@ void NzSkeletalMesh::Destroy() { if (m_impl) { + NotifyDestroy(); + delete m_impl; m_impl = nullptr; } diff --git a/src/Nazara/Utility/StaticMesh.cpp b/src/Nazara/Utility/StaticMesh.cpp index e27cef00a..0a21350b6 100644 --- a/src/Nazara/Utility/StaticMesh.cpp +++ b/src/Nazara/Utility/StaticMesh.cpp @@ -40,14 +40,16 @@ bool NzStaticMesh::Create(NzVertexBuffer* vertexBuffer) void NzStaticMesh::Destroy() { - if (m_indexBuffer) - { - m_indexBuffer->RemoveResourceListener(this); - m_indexBuffer = nullptr; - } - if (m_vertexBuffer) { + NotifyDestroy(); + + if (m_indexBuffer) + { + m_indexBuffer->RemoveResourceListener(this); + m_indexBuffer = nullptr; + } + m_vertexBuffer->RemoveResourceListener(this); m_vertexBuffer = nullptr; } diff --git a/src/Nazara/Utility/VertexBuffer.cpp b/src/Nazara/Utility/VertexBuffer.cpp index 0cb7ab9c5..0f2340fc6 100644 --- a/src/Nazara/Utility/VertexBuffer.cpp +++ b/src/Nazara/Utility/VertexBuffer.cpp @@ -36,6 +36,11 @@ m_vertexCount(vertexBuffer.m_vertexCount) { } +NzVertexBuffer::~NzVertexBuffer() +{ + NotifyDestroy(); +} + bool NzVertexBuffer::Fill(const void* data, unsigned int startVertex, unsigned int length, bool forceDiscard) { unsigned int stride = m_vertexDeclaration->GetStride(); diff --git a/src/Nazara/Utility/VertexDeclaration.cpp b/src/Nazara/Utility/VertexDeclaration.cpp index 62feb9bff..b69ce77a3 100644 --- a/src/Nazara/Utility/VertexDeclaration.cpp +++ b/src/Nazara/Utility/VertexDeclaration.cpp @@ -53,6 +53,11 @@ m_stride(declaration.m_stride) std::memcpy(m_attributes, declaration.m_attributes, sizeof(Attribute)*(nzAttributeUsage_Max+1)); } +NzVertexDeclaration::~NzVertexDeclaration() +{ + NotifyDestroy(); +} + void NzVertexDeclaration::DisableAttribute(nzAttributeUsage usage) { #ifdef NAZARA_DEBUG