From 4f7bc863694652e76e7977a64fa730ae0ca3496f Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Thu, 20 Apr 2023 10:34:18 -0700 Subject: [PATCH 1/3] main: make m_asteroids a unique_ptr Signed-off-by: Lukas Rusak --- src/main.cpp | 8 ++------ src/main.h | 4 +++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 85e4701..e064315 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -86,8 +86,7 @@ const BYTE PixelShader[] = #endif CMyAddon::CMyAddon() - : m_asteroids(nullptr), - m_timer(nullptr) + : m_timer(nullptr) { } @@ -127,9 +126,7 @@ bool CMyAddon::Start() m_Height = Height(); srand((u32)time(nullptr)); - m_asteroids = new CAsteroids(this); - if (!m_asteroids) - return false; + m_asteroids = std::make_unique(this); m_timer = new CTimer(); m_timer->Init(); @@ -179,7 +176,6 @@ void CMyAddon::Stop() #endif m_asteroids->InvalidateDevice(); - SAFE_DELETE(m_asteroids); SAFE_DELETE(m_timer); #ifndef WIN32 diff --git a/src/main.h b/src/main.h index 94e42f3..c46b94a 100644 --- a/src/main.h +++ b/src/main.h @@ -19,6 +19,8 @@ #include #endif +#include + #include #include #include "types.h" @@ -83,7 +85,7 @@ class ATTR_DLL_LOCAL CMyAddon ID3D11PixelShader* m_pPShader; #endif - CAsteroids* m_asteroids; + std::unique_ptr m_asteroids; CTimer* m_timer; }; From 1f7fcd4fdd5a377bf54d9d4a36cb75deb97a982f Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Thu, 20 Apr 2023 10:35:53 -0700 Subject: [PATCH 2/3] main: make m_timer a unique_ptr Signed-off-by: Lukas Rusak --- src/main.cpp | 8 +------- src/main.h | 4 ++-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e064315..bd28e9a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,11 +85,6 @@ const BYTE PixelShader[] = }; #endif -CMyAddon::CMyAddon() - : m_timer(nullptr) -{ -} - //////////////////////////////////////////////////////////////////////////// // Kodi tells us we should get ready to start rendering. This function // is called once when the screensaver is activated by Kodi. @@ -128,7 +123,7 @@ bool CMyAddon::Start() srand((u32)time(nullptr)); m_asteroids = std::make_unique(this); - m_timer = new CTimer(); + m_timer = std::make_unique(); m_timer->Init(); if (!m_asteroids->RestoreDevice()) { @@ -176,7 +171,6 @@ void CMyAddon::Stop() #endif m_asteroids->InvalidateDevice(); - SAFE_DELETE(m_timer); #ifndef WIN32 glBindBuffer(GL_ARRAY_BUFFER, 0); diff --git a/src/main.h b/src/main.h index c46b94a..561397f 100644 --- a/src/main.h +++ b/src/main.h @@ -49,7 +49,7 @@ class ATTR_DLL_LOCAL CMyAddon #endif { public: - CMyAddon(); + CMyAddon() = default; bool Start() override; void Stop() override; @@ -86,7 +86,7 @@ class ATTR_DLL_LOCAL CMyAddon #endif std::unique_ptr m_asteroids; - CTimer* m_timer; + std::unique_ptr m_timer; }; /***************************** I N L I N E S *******************************/ From 26712fea98ee5ef50945970f531b3621099b8b8f Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Thu, 20 Apr 2023 10:48:13 -0700 Subject: [PATCH 3/3] main: use delete[] for array Signed-off-by: Lukas Rusak --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bd28e9a..93f78f9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -176,8 +176,8 @@ void CMyAddon::Stop() glBindBuffer(GL_ARRAY_BUFFER, 0); glDeleteBuffers(1, &m_vertexVBO); m_vertexVBO = 0; - - delete m_VertBuf; + + delete[] m_VertBuf; m_VertBuf = nullptr; #endif }