Fix Segfault caused by losing pointer to std::string
authorDaniel Hritzkiv <daniel.hritzkiv@gmail.com>
Tue, 12 Sep 2017 14:07:15 +0000 (10:07 -0400)
committerDaniel Hritzkiv <daniel.hritzkiv@gmail.com>
Tue, 12 Sep 2017 14:07:15 +0000 (10:07 -0400)
Keep std::string alive

code/glTF2Asset.h
code/glTF2Exporter.cpp

index b093ec0..8604cd2 100644 (file)
@@ -164,7 +164,7 @@ namespace glTF2
     //! Magic number for GLB files
        #define AI_GLB_MAGIC_NUMBER "glTF"
 
-       #define AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLIC_FACTOR "$mat.gltf.pbrMetallicRoughness.metallicFactor", 0,0
+       #define AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLIC_FACTOR "$mat.gltf.pbrMetallicRoughness.metallicFactor", 0, 0
        #define AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_ROUGHNESS_FACTOR "$mat.gltf.pbrMetallicRoughness.roughnessFactor", 0, 0
        #define AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE aiTextureType_UNKNOWN, 0
        #define AI_MATKEY_GLTF_ALPHAMODE "$mat.gltf.alphaMode", 0, 0
@@ -172,15 +172,15 @@ namespace glTF2
        #define AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS "$mat.gltf.pbrSpecularGlossiness", 0, 0
        #define AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS_DIFFUSE_FACTOR "$clr.diffuse", 0, 1
        #define AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS_SPECULAR_FACTOR "$clr.specular", 0, 1
-       #define AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS_GLOSSINESS_FACTOR "$mat.gltf.pbrMetallicRoughness.glossinessFactor", 0,0
+       #define AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS_GLOSSINESS_FACTOR "$mat.gltf.pbrMetallicRoughness.glossinessFactor", 0, 0
        #define AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS_DIFFUSE_TEXTURE aiTextureType_DIFFUSE, 1
        #define AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS_SPECULARGLOSSINESS_TEXTURE aiTextureType_UNKNOWN, 1
 
-       #define _AI_MATKEY_GLTF_TEXTURE_TEXCOORD_BASE (std::string(_AI_MATKEY_TEXTURE_BASE) + ".texCoord").c_str()
-       #define _AI_MATKEY_GLTF_MAPPINGNAME_BASE (std::string(_AI_MATKEY_MAPPING_BASE) + "name").c_str()
-       #define _AI_MATKEY_GLTF_MAPPINGID_BASE  (std::string(_AI_MATKEY_MAPPING_BASE) + "id").c_str()
-       #define _AI_MATKEY_GLTF_MAPPINGFILTER_MAG_BASE (std::string(_AI_MATKEY_MAPPING_BASE) + "filtermag").c_str()
-       #define _AI_MATKEY_GLTF_MAPPINGFILTER_MIN_BASE (std::string(_AI_MATKEY_MAPPING_BASE) + "filtermin").c_str()
+       #define _AI_MATKEY_GLTF_TEXTURE_TEXCOORD_BASE "$tex.file.texCoord"
+       #define _AI_MATKEY_GLTF_MAPPINGNAME_BASE "$tex.mappingname"
+       #define _AI_MATKEY_GLTF_MAPPINGID_BASE "$tex.mappingid"
+       #define _AI_MATKEY_GLTF_MAPPINGFILTER_MAG_BASE "$tex.mappingfiltermag"
+       #define _AI_MATKEY_GLTF_MAPPINGFILTER_MIN_BASE "$tex.mappingfiltermin"
 
        #define AI_MATKEY_GLTF_TEXTURE_TEXCOORD _AI_MATKEY_GLTF_TEXTURE_TEXCOORD_BASE, type, N
        #define AI_MATKEY_GLTF_MAPPINGNAME(type, N) _AI_MATKEY_GLTF_MAPPINGNAME_BASE, type, N
index e2b46b1..9a0e0cc 100644 (file)
@@ -276,16 +276,16 @@ void glTF2Exporter::GetTexSampler(const aiMaterial* mat, Ref<Texture> texture, a
 
 void glTF2Exporter::GetMatTexProp(const aiMaterial* mat, unsigned int& prop, const char* propName, aiTextureType tt, unsigned int slot)
 {
-    const char* key = (std::string(_AI_MATKEY_TEXTURE_BASE) + "." + propName).c_str();
+    std::string textureKey = std::string(_AI_MATKEY_TEXTURE_BASE) + "." + propName;
 
-    mat->Get(key, tt, slot, prop);
+    mat->Get(textureKey.c_str(), tt, slot, prop);
 }
 
 void glTF2Exporter::GetMatTexProp(const aiMaterial* mat, float& prop, const char* propName, aiTextureType tt, unsigned int slot)
 {
-    const char* key = (std::string(_AI_MATKEY_TEXTURE_BASE) + "." + propName).c_str();
+    std::string textureKey = std::string(_AI_MATKEY_TEXTURE_BASE) + "." + propName;
 
-    mat->Get(key, tt, slot, prop);
+    mat->Get(textureKey.c_str(), tt, slot, prop);
 }
 
 void glTF2Exporter::GetMatTex(const aiMaterial* mat, Ref<Texture>& texture, aiTextureType tt, unsigned int slot = 0)