Bläddra i källkod

Merge pull request #3412 from MalcolmTyrrell/fbxReportAssetIssuesProperly

Fbx report asset issues properly
Kim Kulling 4 år sedan
förälder
incheckning
a5a331847b

+ 1 - 1
code/AssetLib/Collada/ColladaExporter.cpp

@@ -573,7 +573,7 @@ bool ColladaExporter::ReadMaterialSurface(Surface &poSurface, const aiMaterial &
             index_str = index_str.substr(1, std::string::npos);
             index_str = index_str.substr(1, std::string::npos);
 
 
             try {
             try {
-                index = (unsigned int)strtoul10_64(index_str.c_str());
+                index = (unsigned int)strtoul10_64<DeadlyExportError>(index_str.c_str());
             } catch (std::exception &error) {
             } catch (std::exception &error) {
                 throw DeadlyExportError(error.what());
                 throw DeadlyExportError(error.what());
             }
             }

+ 5 - 0
code/AssetLib/FBX/FBXImporter.cpp

@@ -187,6 +187,11 @@ void FBXImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
 
 
 		// size relative to cm
 		// size relative to cm
 		float size_relative_to_cm = doc.GlobalSettings().UnitScaleFactor();
 		float size_relative_to_cm = doc.GlobalSettings().UnitScaleFactor();
+        if (size_relative_to_cm == 0.0)
+        {
+			// BaseImporter later asserts that fileScale is non-zero.
+			ThrowException("The UnitScaleFactor must be non-zero");
+        }
 
 
 		// Set FBX file scale is relative to CM must be converted to M for
 		// Set FBX file scale is relative to CM must be converted to M for
 		// assimp universal format (M)
 		// assimp universal format (M)

+ 19 - 12
include/assimp/fast_atof.h

@@ -24,11 +24,11 @@
 #include <cmath>
 #include <cmath>
 #include <limits>
 #include <limits>
 #include <stdint.h>
 #include <stdint.h>
-#include <stdexcept>
 #include <assimp/defs.h>
 #include <assimp/defs.h>
 
 
 #include "StringComparison.h"
 #include "StringComparison.h"
 #include <assimp/DefaultLogger.hpp>
 #include <assimp/DefaultLogger.hpp>
+#include <assimp/Exceptional.h>
 
 
 #ifdef _MSC_VER
 #ifdef _MSC_VER
 #  include <stdint.h>
 #  include <stdint.h>
@@ -185,13 +185,15 @@ unsigned int strtoul_cppstyle( const char* in, const char** out=0) {
 // Special version of the function, providing higher accuracy and safety
 // Special version of the function, providing higher accuracy and safety
 // It is mainly used by fast_atof to prevent ugly and unwanted integer overflows.
 // It is mainly used by fast_atof to prevent ugly and unwanted integer overflows.
 // ------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------
+template<typename ExceptionType = DeadlyImportError>
 inline
 inline
 uint64_t strtoul10_64( const char* in, const char** out=0, unsigned int* max_inout=0) {
 uint64_t strtoul10_64( const char* in, const char** out=0, unsigned int* max_inout=0) {
     unsigned int cur = 0;
     unsigned int cur = 0;
     uint64_t value = 0;
     uint64_t value = 0;
 
 
     if ( *in < '0' || *in > '9' ) {
     if ( *in < '0' || *in > '9' ) {
-        throw std::invalid_argument( std::string( "The string \"" ) + in + "\" cannot be converted into a value." );
+        // The string is known to be bad, so don't risk printing the whole thing.
+        throw ExceptionType("The string \"", std::string(in).substr(0, 100), "\" cannot be converted into a value." );
     }
     }
 
 
     for ( ;; ) {
     for ( ;; ) {
@@ -237,6 +239,7 @@ uint64_t strtoul10_64( const char* in, const char** out=0, unsigned int* max_ino
 // ------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------
 // signed variant of strtoul10_64
 // signed variant of strtoul10_64
 // ------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------
+template<typename ExceptionType = DeadlyImportError>
 inline
 inline
 int64_t strtol10_64(const char* in, const char** out = 0, unsigned int* max_inout = 0) {
 int64_t strtol10_64(const char* in, const char** out = 0, unsigned int* max_inout = 0) {
     bool inv = (*in == '-');
     bool inv = (*in == '-');
@@ -244,7 +247,7 @@ int64_t strtol10_64(const char* in, const char** out = 0, unsigned int* max_inou
         ++in;
         ++in;
     }
     }
 
 
-    int64_t value = strtoul10_64(in, out, max_inout);
+    int64_t value = strtoul10_64<ExceptionType>(in, out, max_inout);
     if (inv) {
     if (inv) {
         value = -value;
         value = -value;
     }
     }
@@ -259,7 +262,7 @@ int64_t strtol10_64(const char* in, const char** out = 0, unsigned int* max_inou
 //! about 6 times faster than atof in win32.
 //! about 6 times faster than atof in win32.
 // If you find any bugs, please send them to me, niko (at) irrlicht3d.org.
 // If you find any bugs, please send them to me, niko (at) irrlicht3d.org.
 // ------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------
-template<typename Real>
+template<typename Real, typename ExceptionType = DeadlyImportError>
 inline
 inline
 const char* fast_atoreal_move(const char* c, Real& out, bool check_comma = true) {
 const char* fast_atoreal_move(const char* c, Real& out, bool check_comma = true) {
     Real f = 0;
     Real f = 0;
@@ -289,13 +292,14 @@ const char* fast_atoreal_move(const char* c, Real& out, bool check_comma = true)
 
 
     if (!(c[0] >= '0' && c[0] <= '9') &&
     if (!(c[0] >= '0' && c[0] <= '9') &&
             !((c[0] == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9')) {
             !((c[0] == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9')) {
-        throw std::invalid_argument("Cannot parse string "
-                                    "as real number: does not start with digit "
+        // The string is known to be bad, so don't risk printing the whole thing.
+        throw ExceptionType("Cannot parse string \"", std::string(c).substr(0, 100), 
+                                    "\" as a real number: does not start with digit "
                                     "or decimal point followed by digit.");
                                     "or decimal point followed by digit.");
     }
     }
 
 
     if (*c != '.' && (! check_comma || c[0] != ',')) {
     if (*c != '.' && (! check_comma || c[0] != ',')) {
-        f = static_cast<Real>( strtoul10_64 ( c, &c) );
+        f = static_cast<Real>( strtoul10_64<ExceptionType> ( c, &c) );
     }
     }
 
 
     if ((*c == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9') {
     if ((*c == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9') {
@@ -310,7 +314,7 @@ const char* fast_atoreal_move(const char* c, Real& out, bool check_comma = true)
         // number of digits to be read. AI_FAST_ATOF_RELAVANT_DECIMALS can be a value between
         // number of digits to be read. AI_FAST_ATOF_RELAVANT_DECIMALS can be a value between
         // 1 and 15.
         // 1 and 15.
         unsigned int diff = AI_FAST_ATOF_RELAVANT_DECIMALS;
         unsigned int diff = AI_FAST_ATOF_RELAVANT_DECIMALS;
-        double pl = static_cast<double>( strtoul10_64 ( c, &c, &diff ));
+        double pl = static_cast<double>( strtoul10_64<ExceptionType> ( c, &c, &diff ));
 
 
         pl *= fast_atof_table[diff];
         pl *= fast_atof_table[diff];
         f += static_cast<Real>( pl );
         f += static_cast<Real>( pl );
@@ -332,7 +336,7 @@ const char* fast_atoreal_move(const char* c, Real& out, bool check_comma = true)
         // The reason float constants are used here is that we've seen cases where compilers
         // The reason float constants are used here is that we've seen cases where compilers
         // would perform such casts on compile-time constants at runtime, which would be
         // would perform such casts on compile-time constants at runtime, which would be
         // bad considering how frequently fast_atoreal_move<float> is called in Assimp.
         // bad considering how frequently fast_atoreal_move<float> is called in Assimp.
-        Real exp = static_cast<Real>( strtoul10_64(c, &c) );
+        Real exp = static_cast<Real>( strtoul10_64<ExceptionType>(c, &c) );
         if (einv) {
         if (einv) {
             exp = -exp;
             exp = -exp;
         }
         }
@@ -348,26 +352,29 @@ const char* fast_atoreal_move(const char* c, Real& out, bool check_comma = true)
 
 
 // ------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------
 // The same but more human.
 // The same but more human.
+template<typename ExceptionType = DeadlyImportError>
 inline
 inline
 ai_real fast_atof(const char* c) {
 ai_real fast_atof(const char* c) {
     ai_real ret(0.0);
     ai_real ret(0.0);
-    fast_atoreal_move<ai_real>(c, ret);
+    fast_atoreal_move<ai_real, ExceptionType>(c, ret);
 
 
     return ret;
     return ret;
 }
 }
 
 
+template<typename ExceptionType = DeadlyImportError>
 inline
 inline
 ai_real fast_atof( const char* c, const char** cout) {
 ai_real fast_atof( const char* c, const char** cout) {
     ai_real ret(0.0);
     ai_real ret(0.0);
-    *cout = fast_atoreal_move<ai_real>(c, ret);
+    *cout = fast_atoreal_move<ai_real, ExceptionType>(c, ret);
 
 
     return ret;
     return ret;
 }
 }
 
 
+template<typename ExceptionType = DeadlyImportError>
 inline
 inline
 ai_real fast_atof( const char** inout) {
 ai_real fast_atof( const char** inout) {
     ai_real ret(0.0);
     ai_real ret(0.0);
-    *inout = fast_atoreal_move<ai_real>(*inout, ret);
+    *inout = fast_atoreal_move<ai_real, ExceptionType>(*inout, ret);
 
 
     return ret;
     return ret;
 }
 }