From 983d55893b85bb57a0eba0d3d4c1914472f8efc2 Mon Sep 17 00:00:00 2001 From: Samuel Felton Date: Thu, 5 Sep 2024 16:30:17 +0200 Subject: [PATCH] Using Panda's managed pointer for texture and buffers to avoid memory leaks --- .../include/visp3/ar/vpPanda3DGeometryRenderer.h | 8 ++++---- .../include/visp3/ar/vpPanda3DPostProcessFilter.h | 12 ++++-------- modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h | 14 +++++++++----- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/modules/ar/include/visp3/ar/vpPanda3DGeometryRenderer.h b/modules/ar/include/visp3/ar/vpPanda3DGeometryRenderer.h index a33c599553..c4540b969a 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DGeometryRenderer.h +++ b/modules/ar/include/visp3/ar/vpPanda3DGeometryRenderer.h @@ -61,7 +61,7 @@ class VISP_EXPORT vpPanda3DGeometryRenderer : public vpPanda3DBaseRenderer }; vpPanda3DGeometryRenderer(vpRenderType renderType); - ~vpPanda3DGeometryRenderer() { } + ~vpPanda3DGeometryRenderer() = default; /** * @brief Get render results into ViSP readable structures @@ -85,7 +85,7 @@ class VISP_EXPORT vpPanda3DGeometryRenderer : public vpPanda3DBaseRenderer */ void getRender(vpImage &depth) const; - GraphicsOutput *getMainOutputBuffer() VP_OVERRIDE { return m_normalDepthBuffer; } + GraphicsOutput *getMainOutputBuffer() VP_OVERRIDE { return (GraphicsOutput *)m_normalDepthBuffer; } protected: @@ -94,8 +94,8 @@ class VISP_EXPORT vpPanda3DGeometryRenderer : public vpPanda3DBaseRenderer private: vpRenderType m_renderType; - Texture *m_normalDepthTexture; - GraphicsOutput *m_normalDepthBuffer; + PointerTo m_normalDepthTexture; + PointerTo m_normalDepthBuffer; static const char *SHADER_VERT_NORMAL_AND_DEPTH_OBJECT; static const char *SHADER_VERT_NORMAL_AND_DEPTH_CAMERA; diff --git a/modules/ar/include/visp3/ar/vpPanda3DPostProcessFilter.h b/modules/ar/include/visp3/ar/vpPanda3DPostProcessFilter.h index abb27399ff..079e4e96a4 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DPostProcessFilter.h +++ b/modules/ar/include/visp3/ar/vpPanda3DPostProcessFilter.h @@ -62,18 +62,14 @@ class VISP_EXPORT vpPanda3DPostProcessFilter : public vpPanda3DBaseRenderer m_renderOrder = m_inputRenderer->getRenderOrder() + 1; } - ~vpPanda3DPostProcessFilter() - { - // delete m_texture; - // delete m_buffer; - } + virtual ~vpPanda3DPostProcessFilter() = default; bool isRendering3DScene() const VP_OVERRIDE { return false; } - GraphicsOutput *getMainOutputBuffer() VP_OVERRIDE { return m_buffer; } + GraphicsOutput *getMainOutputBuffer() VP_OVERRIDE { return (GraphicsOutput *)m_buffer; } void afterFrameRendered() VP_OVERRIDE { @@ -100,8 +96,8 @@ class VISP_EXPORT vpPanda3DPostProcessFilter : public vpPanda3DBaseRenderer bool m_isOutput; //! Whether this filter is an output to be used and should be copied to ram std::string m_fragmentShader; PointerTo m_shader; - Texture *m_texture; - GraphicsOutput *m_buffer; + PointerTo m_texture; + PointerTo m_buffer; static const char *FILTER_VERTEX_SHADER; }; diff --git a/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h b/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h index 06789092a3..cadb5c021e 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h +++ b/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h @@ -39,6 +39,8 @@ #include #include +#include "pointerTo.h" + BEGIN_VISP_NAMESPACE /** * \ingroup group_ar_renderer_panda3d_3d @@ -78,6 +80,8 @@ class VISP_EXPORT vpPanda3DRGBRenderer : public vpPanda3DBaseRenderer, public vp */ vpPanda3DRGBRenderer(bool showSpeculars) : vpPanda3DBaseRenderer(showSpeculars ? "RGB" : "RGB-diffuse"), m_showSpeculars(showSpeculars) { } + virtual ~vpPanda3DRGBRenderer() = default; + /** * @brief Store the render resulting from calling renderFrame() into a vpImage. * @@ -91,7 +95,7 @@ class VISP_EXPORT vpPanda3DRGBRenderer : public vpPanda3DBaseRenderer, public vp void setBackgroundImage(const vpImage &background); - GraphicsOutput *getMainOutputBuffer() VP_OVERRIDE { return m_colorBuffer; } + GraphicsOutput *getMainOutputBuffer() VP_OVERRIDE { return (GraphicsOutput *)m_colorBuffer; } bool isShowingSpeculars() const { return m_showSpeculars; } @@ -103,14 +107,14 @@ class VISP_EXPORT vpPanda3DRGBRenderer : public vpPanda3DBaseRenderer, public vp private: bool m_showSpeculars; - Texture *m_colorTexture; - GraphicsOutput *m_colorBuffer; + PointerTo m_colorTexture; + PointerTo m_colorBuffer; static const char *COOK_TORRANCE_VERT; static const char *COOK_TORRANCE_FRAG; NodePath m_backgroundImage; - DisplayRegion *m_display2d; - Texture *m_backgroundTexture; + PointerTo m_display2d; + PointerTo m_backgroundTexture; }; END_VISP_NAMESPACE