Fix possible nullptr dereferencing.

pull/1832/head
Kim Kulling 2018-03-09 19:03:05 +01:00
parent 69742670dd
commit 6668eeb68e
2 changed files with 40 additions and 4 deletions

View File

@ -49,8 +49,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/IOStream.hpp>
#include <assimp/Exporter.hpp>
#include <assimp/DefaultLogger.hpp>
#include <assimp/StringUtils.h>
#include <assimp/Exceptional.h>
#include "3MFXmlTags.h"
#include "D3MFOpcPackage.h"
@ -204,8 +205,45 @@ void D3MFExporter::writeHeader() {
mModelOutput << std::endl;
}
void D3MFExporter::writeBaseMaterials() {
static std::string to_hex( int to_convert ) {
std::string result;
std::stringstream ss;
ss << std::hex << to_convert;
ss >> result;
return result;
}
void D3MFExporter::writeBaseMaterials() {
mModelOutput << "<basematerials id=\"1\">\n";
for ( size_t i = 0; i < mScene->mNumMaterials; ++i ) {
aiMaterial *mat = mScene->mMaterials[ i ];
std::string strName;
aiString name;
if ( mat->Get( AI_MATKEY_NAME, name ) != aiReturn_SUCCESS ) {
strName = "basemat_" + to_string( i );
} else {
strName = name.C_Str();
}
std::string hexDiffuseColor;
aiColor4D color;
if ( mat->Get( AI_MATKEY_COLOR_DIFFUSE, color ) == aiReturn_SUCCESS ) {
hexDiffuseColor = "#";
std::string tmp;
tmp = to_hex( color.r );
hexDiffuseColor += tmp;
tmp = to_hex( color.g );
hexDiffuseColor += tmp;
tmp = to_hex( color.b );
hexDiffuseColor += tmp;
tmp = to_hex( color.a );
hexDiffuseColor += tmp;
} else {
hexDiffuseColor = "#FFFFFFFF";
}
mModelOutput << "<base name=\""+strName+"\" "+" displaycolor=\""+hexDiffuseColor+"\">\n";
}
mModelOutput << "</basematerials>\n";
}
void D3MFExporter::writeObjects() {

View File

@ -146,7 +146,6 @@ uint8_t HexOctetToDecimal(const char* in) {
return ((uint8_t)HexDigitToDecimal(in[0])<<4)+(uint8_t)HexDigitToDecimal(in[1]);
}
// ------------------------------------------------------------------------------------
// signed variant of strtoul10
// ------------------------------------------------------------------------------------
@ -353,7 +352,6 @@ ai_real fast_atof(const char* c) {
return ret;
}
inline
ai_real fast_atof( const char* c, const char** cout) {
ai_real ret(0.0);