From 504939f1937fae3f2d1212e7dc6f2e7af45adab7 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 13 Jan 2016 14:07:48 -0800 Subject: [PATCH] Use a unique_ptr to track gpu objects --- libraries/gpu/src/gpu/Format.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libraries/gpu/src/gpu/Format.h b/libraries/gpu/src/gpu/Format.h index 1ae579d9f5..61fb1e847e 100644 --- a/libraries/gpu/src/gpu/Format.h +++ b/libraries/gpu/src/gpu/Format.h @@ -11,8 +11,10 @@ #ifndef hifi_gpu_Format_h #define hifi_gpu_Format_h -#include #include +#include + +#include namespace gpu { @@ -25,14 +27,15 @@ public: class GPUObjectWrapper { public: - virtual ~GPUObjectWrapper() { delete _gpuObject; } + virtual ~GPUObjectWrapper() = default; private: + using GPUObjectPointer = std::unique_ptr; + // This shouldn't be used by anything else than the Backend class with the proper casting. - // TODO: Consider using std::unique_ptr to get rid of dtor and ensure correct destruction of GPU objects - mutable GPUObject* _gpuObject { nullptr }; - void setGPUObject(GPUObject* gpuObject) const { _gpuObject = gpuObject; } - GPUObject* getGPUObject() const { return _gpuObject; } + mutable GPUObjectPointer _gpuObject; + void setGPUObject(GPUObject* gpuObject) const { _gpuObject.reset(gpuObject); } + GPUObject* getGPUObject() const { return _gpuObject.get(); } friend class Backend; };