Skip to content

Commit

Permalink
Merge branch 'master' into kimkulling-miniz-memoryaccessfix
Browse files Browse the repository at this point in the history
  • Loading branch information
kimkulling committed Dec 4, 2017
2 parents b92c3ca + 75b3137 commit 98cb898
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .travis.sh
Expand Up @@ -46,7 +46,7 @@ if [ "$TRAVIS_OS_NAME" = "linux" ]; then
if [ $ANALYZE = "ON" ] ; then
if [ "$CC" = "clang" ]; then
scan-build cmake -G "Unix Makefiles" -DBUILD_SHARED_LIBS=OFF -DASSIMP_BUILD_TESTS=OFF
scan-build --status-bugs make -j2 -v
scan-build --status-bugs make -j2
else
cppcheck --version
generate \
Expand Down
7 changes: 3 additions & 4 deletions code/BaseImporter.cpp
Expand Up @@ -89,12 +89,12 @@ aiScene* BaseImporter::ReadFile(const Importer* pImp, const std::string& pFile,
FileSystemFilter filter(pFile,pIOHandler);

// create a scene object to hold the data
ScopeGuard<aiScene> sc(new aiScene());
std::unique_ptr<aiScene> sc(new aiScene());

// dispatch importing
try
{
InternReadFile( pFile, sc, &filter);
InternReadFile( pFile, sc.get(), &filter);

} catch( const std::exception& err ) {
// extract error description
Expand All @@ -104,8 +104,7 @@ aiScene* BaseImporter::ReadFile(const Importer* pImp, const std::string& pFile,
}

// return what we gathered from the import.
sc.dismiss();
return sc;
return sc.release();
}

// ------------------------------------------------------------------------------------------------
Expand Down
36 changes: 0 additions & 36 deletions code/BaseImporter.h
Expand Up @@ -65,42 +65,6 @@ class IOStream;
#define AI_MAKE_MAGIC(string) ((uint32_t)((string[0] << 24) + \
(string[1] << 16) + (string[2] << 8) + string[3]))

// ---------------------------------------------------------------------------
template <typename T>
struct ScopeGuard
{
explicit ScopeGuard(T* obj) : obj(obj), mdismiss() {}
~ScopeGuard () throw() {
if (!mdismiss) {
delete obj;
}
obj = NULL;
}

T* dismiss() {
mdismiss=true;
return obj;
}

operator T*() {
return obj;
}

T* operator -> () {
return obj;
}

private:
// no copying allowed.
ScopeGuard();
ScopeGuard( const ScopeGuard & );
ScopeGuard &operator = ( const ScopeGuard & );

T* obj;
bool mdismiss;
};



// ---------------------------------------------------------------------------
/** FOR IMPORTER PLUGINS ONLY: The BaseImporter defines a common interface
Expand Down
14 changes: 7 additions & 7 deletions code/BlenderLoader.cpp
Expand Up @@ -1148,7 +1148,7 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co
// ------------------------------------------------------------------------------------------------
aiCamera* BlenderImporter::ConvertCamera(const Scene& /*in*/, const Object* obj, const Camera* cam, ConversionData& /*conv_data*/)
{
ScopeGuard<aiCamera> out(new aiCamera());
std::unique_ptr<aiCamera> out(new aiCamera());
out->mName = obj->id.name+2;
out->mPosition = aiVector3D(0.f, 0.f, 0.f);
out->mUp = aiVector3D(0.f, 1.f, 0.f);
Expand All @@ -1159,13 +1159,13 @@ aiCamera* BlenderImporter::ConvertCamera(const Scene& /*in*/, const Object* obj,
out->mClipPlaneNear = cam->clipsta;
out->mClipPlaneFar = cam->clipend;

return out.dismiss();
return out.release();
}

// ------------------------------------------------------------------------------------------------
aiLight* BlenderImporter::ConvertLight(const Scene& /*in*/, const Object* obj, const Lamp* lamp, ConversionData& /*conv_data*/)
{
ScopeGuard<aiLight> out(new aiLight());
std::unique_ptr<aiLight> out(new aiLight());
out->mName = obj->id.name+2;

switch (lamp->type)
Expand Down Expand Up @@ -1203,7 +1203,7 @@ aiLight* BlenderImporter::ConvertLight(const Scene& /*in*/, const Object* obj, c
out->mColorAmbient = aiColor3D(lamp->r, lamp->g, lamp->b) * lamp->energy;
out->mColorSpecular = aiColor3D(lamp->r, lamp->g, lamp->b) * lamp->energy;
out->mColorDiffuse = aiColor3D(lamp->r, lamp->g, lamp->b) * lamp->energy;
return out.dismiss();
return out.release();
}

// ------------------------------------------------------------------------------------------------
Expand All @@ -1221,7 +1221,7 @@ aiNode* BlenderImporter::ConvertNode(const Scene& in, const Object* obj, Convers
++it;
}

ScopeGuard<aiNode> node(new aiNode(obj->id.name+2)); // skip over the name prefix 'OB'
std::unique_ptr<aiNode> node(new aiNode(obj->id.name+2)); // skip over the name prefix 'OB'
if (obj->data) {
switch (obj->type)
{
Expand Down Expand Up @@ -1305,14 +1305,14 @@ aiNode* BlenderImporter::ConvertNode(const Scene& in, const Object* obj, Convers
aiNode** nd = node->mChildren = new aiNode*[node->mNumChildren]();
for (const Object* nobj :children) {
*nd = ConvertNode(in,nobj,conv_data,node->mTransformation * parentTransform);
(*nd++)->mParent = node;
(*nd++)->mParent = node.get();
}
}

// apply modifiers
modifier_cache->ApplyModifiers(*node,conv_data,in,*obj);

return node.dismiss();
return node.release();
}

#endif // ASSIMP_BUILD_NO_BLEND_IMPORTER
8 changes: 4 additions & 4 deletions code/C4DImporter.cpp
Expand Up @@ -185,11 +185,11 @@ void C4DImporter::InternReadFile( const std::string& pFile,
if(mesh->mMaterialIndex >= mat_count) {
++mat_count;

ScopeGuard<aiMaterial> def_material(new aiMaterial());
std::unique_ptr<aiMaterial> def_material(new aiMaterial());
const aiString name(AI_DEFAULT_MATERIAL_NAME);
def_material->AddProperty(&name, AI_MATKEY_NAME);

materials.push_back(def_material.dismiss());
materials.push_back(def_material.release());
break;
}
}
Expand Down Expand Up @@ -412,7 +412,7 @@ aiMesh* C4DImporter::ReadMesh(BaseObject* object)
const CPolygon* polys = polyObject->GetPolygonR();
ai_assert(polys != NULL);

ScopeGuard<aiMesh> mesh(new aiMesh());
std::unique_ptr<aiMesh> mesh(new aiMesh());
mesh->mNumFaces = static_cast<unsigned int>(polyCount);
aiFace* face = mesh->mFaces = new aiFace[mesh->mNumFaces]();

Expand Down Expand Up @@ -616,7 +616,7 @@ aiMesh* C4DImporter::ReadMesh(BaseObject* object)
}

mesh->mMaterialIndex = ResolveMaterial(polyObject);
return mesh.dismiss();
return mesh.release();
}


Expand Down
4 changes: 2 additions & 2 deletions code/D3MFImporter.cpp
Expand Up @@ -106,7 +106,7 @@ class XmlSerializer {
private:
aiNode* ReadObject(aiScene* scene)
{
ScopeGuard<aiNode> node(new aiNode());
std::unique_ptr<aiNode> node(new aiNode());

std::vector<unsigned long> meshIds;

Expand Down Expand Up @@ -146,7 +146,7 @@ class XmlSerializer {

std::copy(meshIds.begin(), meshIds.end(), node->mMeshes);

return node.dismiss();
return node.release();

}

Expand Down
28 changes: 14 additions & 14 deletions code/FBXConverter.cpp
Expand Up @@ -2744,10 +2744,10 @@ aiNodeAnim* Converter::GenerateRotationNodeAnim( const std::string& name,
double& max_time,
double& min_time )
{
ScopeGuard<aiNodeAnim> na( new aiNodeAnim() );
std::unique_ptr<aiNodeAnim> na( new aiNodeAnim() );
na->mNodeName.Set( name );

ConvertRotationKeys( na, curves, layer_map, start, stop, max_time, min_time, target.RotationOrder() );
ConvertRotationKeys( na.get(), curves, layer_map, start, stop, max_time, min_time, target.RotationOrder() );

// dummy scaling key
na->mScalingKeys = new aiVectorKey[ 1 ];
Expand All @@ -2763,7 +2763,7 @@ aiNodeAnim* Converter::GenerateRotationNodeAnim( const std::string& name,
na->mPositionKeys[ 0 ].mTime = 0.;
na->mPositionKeys[ 0 ].mValue = aiVector3D();

return na.dismiss();
return na.release();
}

aiNodeAnim* Converter::GenerateScalingNodeAnim( const std::string& name,
Expand All @@ -2774,10 +2774,10 @@ aiNodeAnim* Converter::GenerateScalingNodeAnim( const std::string& name,
double& max_time,
double& min_time )
{
ScopeGuard<aiNodeAnim> na( new aiNodeAnim() );
std::unique_ptr<aiNodeAnim> na( new aiNodeAnim() );
na->mNodeName.Set( name );

ConvertScaleKeys( na, curves, layer_map, start, stop, max_time, min_time );
ConvertScaleKeys( na.get(), curves, layer_map, start, stop, max_time, min_time );

// dummy rotation key
na->mRotationKeys = new aiQuatKey[ 1 ];
Expand All @@ -2793,7 +2793,7 @@ aiNodeAnim* Converter::GenerateScalingNodeAnim( const std::string& name,
na->mPositionKeys[ 0 ].mTime = 0.;
na->mPositionKeys[ 0 ].mValue = aiVector3D();

return na.dismiss();
return na.release();
}


Expand All @@ -2806,10 +2806,10 @@ aiNodeAnim* Converter::GenerateTranslationNodeAnim( const std::string& name,
double& min_time,
bool inverse )
{
ScopeGuard<aiNodeAnim> na( new aiNodeAnim() );
std::unique_ptr<aiNodeAnim> na( new aiNodeAnim() );
na->mNodeName.Set( name );

ConvertTranslationKeys( na, curves, layer_map, start, stop, max_time, min_time );
ConvertTranslationKeys( na.get(), curves, layer_map, start, stop, max_time, min_time );

if ( inverse ) {
for ( unsigned int i = 0; i < na->mNumPositionKeys; ++i ) {
Expand All @@ -2831,7 +2831,7 @@ aiNodeAnim* Converter::GenerateTranslationNodeAnim( const std::string& name,
na->mRotationKeys[ 0 ].mTime = 0.;
na->mRotationKeys[ 0 ].mValue = aiQuaternion();

return na.dismiss();
return na.release();
}

aiNodeAnim* Converter::GenerateSimpleNodeAnim( const std::string& name,
Expand All @@ -2845,7 +2845,7 @@ aiNodeAnim* Converter::GenerateSimpleNodeAnim( const std::string& name,
bool reverse_order )

{
ScopeGuard<aiNodeAnim> na( new aiNodeAnim() );
std::unique_ptr<aiNodeAnim> na( new aiNodeAnim() );
na->mNodeName.Set( name );

const PropertyTable& props = target.Props();
Expand Down Expand Up @@ -2917,7 +2917,7 @@ aiNodeAnim* Converter::GenerateSimpleNodeAnim( const std::string& name,
// which requires all of rotation, scaling and translation
// to be set.
if ( chain[ TransformationComp_Scaling ] != iter_end ) {
ConvertScaleKeys( na, ( *chain[ TransformationComp_Scaling ] ).second,
ConvertScaleKeys( na.get(), ( *chain[ TransformationComp_Scaling ] ).second,
layer_map,
start, stop,
max_time,
Expand All @@ -2933,7 +2933,7 @@ aiNodeAnim* Converter::GenerateSimpleNodeAnim( const std::string& name,
}

if ( chain[ TransformationComp_Rotation ] != iter_end ) {
ConvertRotationKeys( na, ( *chain[ TransformationComp_Rotation ] ).second,
ConvertRotationKeys( na.get(), ( *chain[ TransformationComp_Rotation ] ).second,
layer_map,
start, stop,
max_time,
Expand All @@ -2951,7 +2951,7 @@ aiNodeAnim* Converter::GenerateSimpleNodeAnim( const std::string& name,
}

if ( chain[ TransformationComp_Translation ] != iter_end ) {
ConvertTranslationKeys( na, ( *chain[ TransformationComp_Translation ] ).second,
ConvertTranslationKeys( na.get(), ( *chain[ TransformationComp_Translation ] ).second,
layer_map,
start, stop,
max_time,
Expand All @@ -2967,7 +2967,7 @@ aiNodeAnim* Converter::GenerateSimpleNodeAnim( const std::string& name,
}

}
return na.dismiss();
return na.release();
}

Converter::KeyFrameListList Converter::GetKeyframeList( const std::vector<const AnimationCurveNode*>& nodes, int64_t start, int64_t stop )
Expand Down
6 changes: 3 additions & 3 deletions code/MD3Loader.cpp
Expand Up @@ -1018,11 +1018,11 @@ void MD3Importer::InternReadFile( const std::string& pFile,

// Convert the normal vector to uncompressed float3 format
aiVector3D& nor = pcMesh->mNormals[iCurrent];
LatLngNormalToVec3(pcVertices[pcTriangles->INDEXES[c]].NORMAL,(ai_real*)&nor);
LatLngNormalToVec3(pcVertices[index].NORMAL,(ai_real*)&nor);

// Read texture coordinates
pcMesh->mTextureCoords[0][iCurrent].x = pcUVs[ pcTriangles->INDEXES[c]].U;
pcMesh->mTextureCoords[0][iCurrent].y = 1.0f-pcUVs[ pcTriangles->INDEXES[c]].V;
pcMesh->mTextureCoords[0][iCurrent].x = pcUVs[index].U;
pcMesh->mTextureCoords[0][iCurrent].y = 1.0f-pcUVs[index].V;
}
// Flip face order if necessary
if (!shader || shader->cull == Q3Shader::CULL_CW) {
Expand Down
7 changes: 7 additions & 0 deletions code/STLLoader.cpp
Expand Up @@ -58,6 +58,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace Assimp;

namespace {

static const aiImporterDesc desc = {
"Stereolithography (STL) Importer",
"",
Expand Down Expand Up @@ -505,6 +506,12 @@ bool STLImporter::LoadBinaryFile()
// now copy faces
addFacesToMesh(pMesh);

// add all created meshes to the single node
pScene->mRootNode->mNumMeshes = pScene->mNumMeshes;
pScene->mRootNode->mMeshes = new unsigned int[pScene->mNumMeshes];
for (unsigned int i = 0; i < pScene->mNumMeshes; i++)
pScene->mRootNode->mMeshes[i] = i;

if (bIsMaterialise && !pMesh->mColors[0])
{
// use the color as diffuse material color
Expand Down

0 comments on commit 98cb898

Please sign in to comment.