From 8438defb24d04bcf91b7aa1c18d4e3dbb969a2cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 4 Feb 2018 13:38:44 +0100 Subject: [PATCH] Fix some memory leaks --- ext/native/thin3d/thin3d.cpp | 14 +++++++++++--- ext/native/thin3d/thin3d.h | 1 + ext/native/thin3d/thin3d_gl.cpp | 2 ++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ext/native/thin3d/thin3d.cpp b/ext/native/thin3d/thin3d.cpp index 0cde248021..98827edda9 100644 --- a/ext/native/thin3d/thin3d.cpp +++ b/ext/native/thin3d/thin3d.cpp @@ -336,17 +336,25 @@ bool DrawContext::CreatePresets() { return vsPresets_[VS_TEXTURE_COLOR_2D] && vsPresets_[VS_COLOR_2D] && fsPresets_[FS_TEXTURE_COLOR_2D] && fsPresets_[FS_COLOR_2D]; } -DrawContext::~DrawContext() { +void DrawContext::DestroyPresets() { for (int i = 0; i < VS_MAX_PRESET; i++) { - if (vsPresets_[i]) + if (vsPresets_[i]) { vsPresets_[i]->Release(); + vsPresets_[i] = nullptr; + } } for (int i = 0; i < FS_MAX_PRESET; i++) { - if (fsPresets_[i]) + if (fsPresets_[i]) { fsPresets_[i]->Release(); + fsPresets_[i] = nullptr; + } } } +DrawContext::~DrawContext() { + DestroyPresets(); +} + // TODO: SSE/NEON // Could also make C fake-simd for 64-bit, two 8888 pixels fit in a register :) void ConvertFromRGBA8888(uint8_t *dst, const uint8_t *src, uint32_t dstStride, uint32_t srcStride, uint32_t width, uint32_t height, DataFormat format) { diff --git a/ext/native/thin3d/thin3d.h b/ext/native/thin3d/thin3d.h index 46f6aaf38e..cbd46e2d4a 100644 --- a/ext/native/thin3d/thin3d.h +++ b/ext/native/thin3d/thin3d.h @@ -543,6 +543,7 @@ class DrawContext { public: virtual ~DrawContext(); bool CreatePresets(); + void DestroyPresets(); virtual const DeviceCaps &GetDeviceCaps() const = 0; virtual uint32_t GetDataFormatSupport(DataFormat fmt) const = 0; diff --git a/ext/native/thin3d/thin3d_gl.cpp b/ext/native/thin3d/thin3d_gl.cpp index 55691e84b9..91868b4095 100644 --- a/ext/native/thin3d/thin3d_gl.cpp +++ b/ext/native/thin3d/thin3d_gl.cpp @@ -527,6 +527,7 @@ OpenGLContext::OpenGLContext() { } OpenGLContext::~OpenGLContext() { + DestroyPresets(); for (int i = 0; i < GLRenderManager::MAX_INFLIGHT_FRAMES; i++) { renderManager_.UnregisterPushBuffer(i, frameData_[i].push); frameData_[i].push->Destroy(); @@ -1031,6 +1032,7 @@ DrawContext *T3DCreateGLContext() { } OpenGLInputLayout::~OpenGLInputLayout() { + render_->DeleteInputLayout(inputLayout_); } void OpenGLInputLayout::Compile(const InputLayoutDesc &desc) {