diff --git a/src/celengine/meshmanager.cpp b/src/celengine/meshmanager.cpp index 3d27dd77..29be9c62 100644 --- a/src/celengine/meshmanager.cpp +++ b/src/celengine/meshmanager.cpp @@ -36,6 +36,7 @@ #include #include #include +#include using namespace cmod; @@ -196,7 +197,7 @@ Geometry* GeometryInfo::load(const string& resolvedFilename) originalMaterialCount, model->getMaterialCount()); - return new ModelGeometry(model); + return new ModelGeometry(unique_ptr(model)); } else { diff --git a/src/celengine/modelgeometry.cpp b/src/celengine/modelgeometry.cpp index 83de1948..58e089cd 100644 --- a/src/celengine/modelgeometry.cpp +++ b/src/celengine/modelgeometry.cpp @@ -51,17 +51,10 @@ public: /** Create a new ModelGeometry wrapping the specified model. * The ModelGeoemtry takes ownership of the model. */ -ModelGeometry::ModelGeometry(Model* model) : - m_model(model) +ModelGeometry::ModelGeometry(unique_ptr&& model) : + m_model(move(model)), + m_glData(unique_ptr(new ModelOpenGLData())) { - m_glData = new ModelOpenGLData(); -} - - -ModelGeometry::~ModelGeometry() -{ - delete m_model; - delete m_glData; } diff --git a/src/celengine/modelgeometry.h b/src/celengine/modelgeometry.h index 21629004..d094ec72 100644 --- a/src/celengine/modelgeometry.h +++ b/src/celengine/modelgeometry.h @@ -14,6 +14,7 @@ #include "geometry.h" #include #include +#include class CelestiaTextureResource : public cmod::Material::TextureResource @@ -40,8 +41,8 @@ class ModelOpenGLData; class ModelGeometry : public Geometry { public: - ModelGeometry(cmod::Model* model); - ~ModelGeometry(); + ModelGeometry(std::unique_ptr&& model); + ~ModelGeometry() = default; /*! Find the closest intersection between the ray and the * model. If the ray intersects the model, return true @@ -60,9 +61,9 @@ class ModelGeometry : public Geometry void loadTextures(); private: - cmod::Model* m_model; + std::unique_ptr m_model; bool m_vbInitialized{ false }; - ModelOpenGLData* m_glData{ nullptr }; + std::unique_ptr m_glData; }; #endif // !_CELENGINE_MODEL_H_