Commit ae57c469 authored by Brian Sidebotham's avatar Brian Sidebotham

Move S3D_MESH* to smart pointer to fix CID 108646

parent c519eea1
...@@ -68,13 +68,6 @@ S3D_MESH::S3D_MESH() ...@@ -68,13 +68,6 @@ S3D_MESH::S3D_MESH()
S3D_MESH::~S3D_MESH() S3D_MESH::~S3D_MESH()
{ {
for( unsigned int idx = 0; idx < childs.size(); idx++ )
{
if( childs[idx] )
{
delete childs[idx];
}
}
} }
......
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#ifndef __3D_MESH_MODEL_H__ #ifndef __3D_MESH_MODEL_H__
#define __3D_MESH_MODEL_H__ #define __3D_MESH_MODEL_H__
#include <memory>
#include <boost/shared_ptr.hpp>
#include <vector> #include <vector>
#define GLM_FORCE_RADIANS #define GLM_FORCE_RADIANS
#include <gal/opengl/glm/glm.hpp> #include <gal/opengl/glm/glm.hpp>
...@@ -37,9 +39,14 @@ ...@@ -37,9 +39,14 @@
#include "3d_material.h" #include "3d_material.h"
#include "CBBox.h" #include "CBBox.h"
class S3D_MESH; class S3D_MESH;
/** A smart pointer to an S3D_MESH object */
typedef boost::shared_ptr<S3D_MESH> S3D_MESH_PTR;
/** A container of smar S3D_MESH object pointers */
typedef std::vector<S3D_MESH_PTR> S3D_MESH_PTRS;
class S3D_MESH class S3D_MESH
{ {
public: public:
...@@ -60,7 +67,7 @@ public: ...@@ -60,7 +67,7 @@ public:
std::vector< S3D_VERTEX > m_PerFaceNormalsNormalized; std::vector< S3D_VERTEX > m_PerFaceNormalsNormalized;
std::vector< S3D_VERTEX > m_PerVertexNormalsNormalized; std::vector< S3D_VERTEX > m_PerVertexNormalsNormalized;
std::vector< int > m_MaterialIndex; std::vector< int > m_MaterialIndex;
std::vector< S3D_MESH * > childs; S3D_MESH_PTRS childs;
S3D_VERTEX m_translation; S3D_VERTEX m_translation;
glm::vec4 m_rotation; glm::vec4 m_rotation;
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#define MODELPARSERS_H #define MODELPARSERS_H
#include <map> #include <map>
#include <memory>
#include <vector> #include <vector>
#include <wx/string.h> #include <wx/string.h>
#include <3d_mesh_model.h> #include <3d_mesh_model.h>
...@@ -75,7 +76,7 @@ public: ...@@ -75,7 +76,7 @@ public:
return false; return false;
}; };
std::vector< S3D_MESH* > childs; S3D_MESH_PTRS childs;
private: private:
S3D_MASTER* master; S3D_MASTER* master;
...@@ -127,7 +128,7 @@ public: ...@@ -127,7 +128,7 @@ public:
private: private:
wxString m_Filename; wxString m_Filename;
S3D_MESH* m_model; S3D_MESH_PTR m_model;
std::vector< wxString > vrml_materials; std::vector< wxString > vrml_materials;
std::vector< wxString > vrml_points; std::vector< wxString > vrml_points;
...@@ -143,7 +144,7 @@ private: ...@@ -143,7 +144,7 @@ private:
typedef std::map< std::string, std::vector< glm::vec3 > > VRML2_COORDINATE_MAP; typedef std::map< std::string, std::vector< glm::vec3 > > VRML2_COORDINATE_MAP;
typedef std::map< std::string, S3D_MESH* > VRML2_DEF_GROUP_MAP; typedef std::map< std::string, S3D_MESH_PTR > VRML2_DEF_GROUP_MAP;
/** /**
* class VRML2_MODEL_PARSER * class VRML2_MODEL_PARSER
...@@ -164,7 +165,7 @@ public: ...@@ -164,7 +165,7 @@ public:
* @param aTransformationModel a model with translation, rotation and scale to apply to default root * @param aTransformationModel a model with translation, rotation and scale to apply to default root
* @return bool - true if finnished with success * @return bool - true if finnished with success
*/ */
bool Load( const wxString& aFilename, S3D_MESH *aTransformationModel ); bool Load( const wxString& aFilename, S3D_MESH_PTR aTransformationModel );
/** /**
* Return string representing VRML2 file in vrml2 format * Return string representing VRML2 file in vrml2 format
...@@ -174,7 +175,7 @@ public: ...@@ -174,7 +175,7 @@ public:
wxString VRML2_representation(); wxString VRML2_representation();
private: private:
int loadFileModel( S3D_MESH *transformationModel ); int loadFileModel( S3D_MESH_PTR transformationModel );
int read_Transform(); int read_Transform();
int read_DEF(); int read_DEF();
int read_DEF_Coordinate(); int read_DEF_Coordinate();
...@@ -211,7 +212,7 @@ private: ...@@ -211,7 +212,7 @@ private:
bool m_normalPerVertex; bool m_normalPerVertex;
bool colorPerVertex; bool colorPerVertex;
S3D_MESH* m_model; ///< It stores the current model that the parsing is adding data S3D_MESH_PTR m_model; ///< It stores the current model that the parsing is adding data
FILE* m_file; FILE* m_file;
wxFileName m_Filename; wxFileName m_Filename;
VRML2_COORDINATE_MAP m_defCoordinateMap; VRML2_COORDINATE_MAP m_defCoordinateMap;
...@@ -266,7 +267,7 @@ private: ...@@ -266,7 +267,7 @@ private:
bool m_normalPerVertex; bool m_normalPerVertex;
bool colorPerVertex; bool colorPerVertex;
S3D_MESH* m_model; S3D_MESH_PTR m_model;
FILE* m_file; FILE* m_file;
wxString m_Filename; wxString m_Filename;
S3D_MODEL_PARSER* m_ModelParser; S3D_MODEL_PARSER* m_ModelParser;
......
...@@ -51,7 +51,7 @@ VRML1_MODEL_PARSER::VRML1_MODEL_PARSER( S3D_MODEL_PARSER* aModelParser ) ...@@ -51,7 +51,7 @@ VRML1_MODEL_PARSER::VRML1_MODEL_PARSER( S3D_MODEL_PARSER* aModelParser )
{ {
m_ModelParser = aModelParser; m_ModelParser = aModelParser;
m_Master = m_ModelParser->GetMaster(); m_Master = m_ModelParser->GetMaster();
m_model = NULL; m_model.reset();
m_file = NULL; m_file = NULL;
m_normalPerVertex = true; m_normalPerVertex = true;
colorPerVertex = true; colorPerVertex = true;
...@@ -88,7 +88,7 @@ bool VRML1_MODEL_PARSER::Load( const wxString& aFilename ) ...@@ -88,7 +88,7 @@ bool VRML1_MODEL_PARSER::Load( const wxString& aFilename )
if( strcmp( text, "Separator" ) == 0 ) if( strcmp( text, "Separator" ) == 0 )
{ {
m_model = new S3D_MESH(); m_model.reset( new S3D_MESH() );
m_ModelParser->childs.push_back( m_model ); m_ModelParser->childs.push_back( m_model );
read_separator(); read_separator();
} }
...@@ -122,18 +122,18 @@ int VRML1_MODEL_PARSER::read_separator() ...@@ -122,18 +122,18 @@ int VRML1_MODEL_PARSER::read_separator()
} }
else if( strcmp( text, "Separator" ) == 0 ) else if( strcmp( text, "Separator" ) == 0 )
{ {
S3D_MESH* parent = m_model; S3D_MESH_PTR parent( m_model.get() );
S3D_MESH* new_mesh_model = new S3D_MESH(); S3D_MESH_PTR new_mesh_model( new S3D_MESH() );
m_model->childs.push_back( new_mesh_model ); m_model->childs.push_back( new_mesh_model );
m_model = new_mesh_model; m_model.reset( new_mesh_model.get() );
// recursive // recursive
read_separator(); read_separator();
m_model = parent; m_model.reset( parent.get() );
} }
else if( ( *text != '}' ) ) else if( ( *text != '}' ) )
{ {
......
This diff is collapsed.
...@@ -45,14 +45,6 @@ VRML_MODEL_PARSER::VRML_MODEL_PARSER( S3D_MASTER* aMaster ) : ...@@ -45,14 +45,6 @@ VRML_MODEL_PARSER::VRML_MODEL_PARSER( S3D_MASTER* aMaster ) :
VRML_MODEL_PARSER::~VRML_MODEL_PARSER() VRML_MODEL_PARSER::~VRML_MODEL_PARSER()
{ {
for( unsigned int idx = 0; idx < childs.size(); idx++ )
{
if( childs[idx] )
{
delete childs[idx];
childs[idx] = 0;
}
}
} }
bool VRML_MODEL_PARSER::Load( const wxString& aFilename ) bool VRML_MODEL_PARSER::Load( const wxString& aFilename )
......
...@@ -52,20 +52,12 @@ static const wxChar* traceX3DParser = wxT( "KI_TRACE_X3D_PARSER" ); ...@@ -52,20 +52,12 @@ static const wxChar* traceX3DParser = wxT( "KI_TRACE_X3D_PARSER" );
X3D_MODEL_PARSER::X3D_MODEL_PARSER( S3D_MASTER* aMaster ) : X3D_MODEL_PARSER::X3D_MODEL_PARSER( S3D_MASTER* aMaster ) :
S3D_MODEL_PARSER( aMaster ) S3D_MODEL_PARSER( aMaster )
{ {
m_model = NULL; m_model.reset();
} }
X3D_MODEL_PARSER::~X3D_MODEL_PARSER() X3D_MODEL_PARSER::~X3D_MODEL_PARSER()
{ {
for( unsigned int idx = 0; idx < childs.size(); idx++ )
{
if( childs[idx] )
{
delete childs[idx];
childs[idx] = 0;
}
}
} }
...@@ -102,7 +94,7 @@ bool X3D_MODEL_PARSER::Load( const wxString& aFilename ) ...@@ -102,7 +94,7 @@ bool X3D_MODEL_PARSER::Load( const wxString& aFilename )
node_it != transforms.end(); node_it != transforms.end();
node_it++ ) node_it++ )
{ {
m_model = new S3D_MESH(); m_model.reset( new S3D_MESH() );
childs.push_back( m_model ); childs.push_back( m_model );
readTransform( *node_it ); readTransform( *node_it );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment