Merge pull request #1753 from turol/threadsafe

Fix thread-safety false positives in Ogre importer
pull/1755/head
Turo Lamminen 2018-01-30 21:56:52 +02:00 committed by GitHub
commit 0780d2daae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 71 deletions

View File

@ -72,11 +72,11 @@ AI_WONT_RETURN void ThrowAttibuteError(const XmlReader* reader, const std::strin
} }
template<> template<>
int32_t OgreXmlSerializer::ReadAttribute<int32_t>(const std::string &name) const int32_t OgreXmlSerializer::ReadAttribute<int32_t>(const char *name) const
{ {
if (HasAttribute(name.c_str())) if (HasAttribute(name))
{ {
return static_cast<int32_t>(m_reader->getAttributeValueAsInt(name.c_str())); return static_cast<int32_t>(m_reader->getAttributeValueAsInt(name));
} }
else else
{ {
@ -86,9 +86,9 @@ int32_t OgreXmlSerializer::ReadAttribute<int32_t>(const std::string &name) const
} }
template<> template<>
uint32_t OgreXmlSerializer::ReadAttribute<uint32_t>(const std::string &name) const uint32_t OgreXmlSerializer::ReadAttribute<uint32_t>(const char *name) const
{ {
if (HasAttribute(name.c_str())) if (HasAttribute(name))
{ {
/** @note This is hackish. But we are never expecting unsigned values that go outside the /** @note This is hackish. But we are never expecting unsigned values that go outside the
int32_t range. Just monitor for negative numbers and kill the import. */ int32_t range. Just monitor for negative numbers and kill the import. */
@ -110,9 +110,9 @@ uint32_t OgreXmlSerializer::ReadAttribute<uint32_t>(const std::string &name) con
} }
template<> template<>
uint16_t OgreXmlSerializer::ReadAttribute<uint16_t>(const std::string &name) const uint16_t OgreXmlSerializer::ReadAttribute<uint16_t>(const char *name) const
{ {
if (HasAttribute(name.c_str())) if (HasAttribute(name))
{ {
return static_cast<uint16_t>(ReadAttribute<uint32_t>(name)); return static_cast<uint16_t>(ReadAttribute<uint32_t>(name));
} }
@ -124,11 +124,11 @@ uint16_t OgreXmlSerializer::ReadAttribute<uint16_t>(const std::string &name) con
} }
template<> template<>
float OgreXmlSerializer::ReadAttribute<float>(const std::string &name) const float OgreXmlSerializer::ReadAttribute<float>(const char *name) const
{ {
if (HasAttribute(name.c_str())) if (HasAttribute(name))
{ {
return m_reader->getAttributeValueAsFloat(name.c_str()); return m_reader->getAttributeValueAsFloat(name);
} }
else else
{ {
@ -138,9 +138,9 @@ float OgreXmlSerializer::ReadAttribute<float>(const std::string &name) const
} }
template<> template<>
std::string OgreXmlSerializer::ReadAttribute<std::string>(const std::string &name) const std::string OgreXmlSerializer::ReadAttribute<std::string>(const char *name) const
{ {
const char* value = m_reader->getAttributeValue(name.c_str()); const char* value = m_reader->getAttributeValue(name);
if (value) if (value)
{ {
return std::string(value); return std::string(value);
@ -153,7 +153,7 @@ std::string OgreXmlSerializer::ReadAttribute<std::string>(const std::string &nam
} }
template<> template<>
bool OgreXmlSerializer::ReadAttribute<bool>(const std::string &name) const bool OgreXmlSerializer::ReadAttribute<bool>(const char *name) const
{ {
std::string value = Ogre::ToLower(ReadAttribute<std::string>(name)); std::string value = Ogre::ToLower(ReadAttribute<std::string>(name));
if (ASSIMP_stricmp(value, "true") == 0) if (ASSIMP_stricmp(value, "true") == 0)
@ -171,9 +171,9 @@ bool OgreXmlSerializer::ReadAttribute<bool>(const std::string &name) const
} }
} }
bool OgreXmlSerializer::HasAttribute(const std::string &name) const bool OgreXmlSerializer::HasAttribute(const char *name) const
{ {
return (m_reader->getAttributeValue(name.c_str()) != 0); return (m_reader->getAttributeValue(name) != 0);
} }
std::string &OgreXmlSerializer::NextNode() std::string &OgreXmlSerializer::NextNode()
@ -231,75 +231,75 @@ std::string &OgreXmlSerializer::SkipCurrentNode()
// Mesh XML constants // Mesh XML constants
// <mesh> // <mesh>
const std::string nnMesh = "mesh"; const char *nnMesh = "mesh";
const std::string nnSharedGeometry = "sharedgeometry"; const char *nnSharedGeometry = "sharedgeometry";
const std::string nnSubMeshes = "submeshes"; const char *nnSubMeshes = "submeshes";
const std::string nnSubMesh = "submesh"; const char *nnSubMesh = "submesh";
const std::string nnSubMeshNames = "submeshnames"; const char *nnSubMeshNames = "submeshnames";
const std::string nnSkeletonLink = "skeletonlink"; const char *nnSkeletonLink = "skeletonlink";
const std::string nnLOD = "levelofdetail"; const char *nnLOD = "levelofdetail";
const std::string nnExtremes = "extremes"; const char *nnExtremes = "extremes";
const std::string nnPoses = "poses"; const char *nnPoses = "poses";
const std::string nnAnimations = "animations"; const char *nnAnimations = "animations";
// <submesh> // <submesh>
const std::string nnFaces = "faces"; const char *nnFaces = "faces";
const std::string nnFace = "face"; const char *nnFace = "face";
const std::string nnGeometry = "geometry"; const char *nnGeometry = "geometry";
const std::string nnTextures = "textures"; const char *nnTextures = "textures";
// <mesh/submesh> // <mesh/submesh>
const std::string nnBoneAssignments = "boneassignments"; const char *nnBoneAssignments = "boneassignments";
// <sharedgeometry/geometry> // <sharedgeometry/geometry>
const std::string nnVertexBuffer = "vertexbuffer"; const char *nnVertexBuffer = "vertexbuffer";
// <vertexbuffer> // <vertexbuffer>
const std::string nnVertex = "vertex"; const char *nnVertex = "vertex";
const std::string nnPosition = "position"; const char *nnPosition = "position";
const std::string nnNormal = "normal"; const char *nnNormal = "normal";
const std::string nnTangent = "tangent"; const char *nnTangent = "tangent";
const std::string nnBinormal = "binormal"; const char *nnBinormal = "binormal";
const std::string nnTexCoord = "texcoord"; const char *nnTexCoord = "texcoord";
const std::string nnColorDiffuse = "colour_diffuse"; const char *nnColorDiffuse = "colour_diffuse";
const std::string nnColorSpecular = "colour_specular"; const char *nnColorSpecular = "colour_specular";
// <boneassignments> // <boneassignments>
const std::string nnVertexBoneAssignment = "vertexboneassignment"; const char *nnVertexBoneAssignment = "vertexboneassignment";
// Skeleton XML constants // Skeleton XML constants
// <skeleton> // <skeleton>
const std::string nnSkeleton = "skeleton"; const char *nnSkeleton = "skeleton";
const std::string nnBones = "bones"; const char *nnBones = "bones";
const std::string nnBoneHierarchy = "bonehierarchy"; const char *nnBoneHierarchy = "bonehierarchy";
const std::string nnAnimationLinks = "animationlinks"; const char *nnAnimationLinks = "animationlinks";
// <bones> // <bones>
const std::string nnBone = "bone"; const char *nnBone = "bone";
const std::string nnRotation = "rotation"; const char *nnRotation = "rotation";
const std::string nnAxis = "axis"; const char *nnAxis = "axis";
const std::string nnScale = "scale"; const char *nnScale = "scale";
// <bonehierarchy> // <bonehierarchy>
const std::string nnBoneParent = "boneparent"; const char *nnBoneParent = "boneparent";
// <animations> // <animations>
const std::string nnAnimation = "animation"; const char *nnAnimation = "animation";
const std::string nnTracks = "tracks"; const char *nnTracks = "tracks";
// <tracks> // <tracks>
const std::string nnTrack = "track"; const char *nnTrack = "track";
const std::string nnKeyFrames = "keyframes"; const char *nnKeyFrames = "keyframes";
const std::string nnKeyFrame = "keyframe"; const char *nnKeyFrame = "keyframe";
const std::string nnTranslate = "translate"; const char *nnTranslate = "translate";
const std::string nnRotate = "rotate"; const char *nnRotate = "rotate";
// Common XML constants // Common XML constants
const std::string anX = "x"; const char *anX = "x";
const std::string anY = "y"; const char *anY = "y";
const std::string anZ = "z"; const char *anZ = "z";
// Mesh // Mesh
@ -538,13 +538,13 @@ void OgreXmlSerializer::ReadGeometryVertexBuffer(VertexDataXml *dest)
void OgreXmlSerializer::ReadSubMesh(MeshXml *mesh) void OgreXmlSerializer::ReadSubMesh(MeshXml *mesh)
{ {
static const std::string anMaterial = "material"; static const char *anMaterial = "material";
static const std::string anUseSharedVertices = "usesharedvertices"; static const char *anUseSharedVertices = "usesharedvertices";
static const std::string anCount = "count"; static const char *anCount = "count";
static const std::string anV1 = "v1"; static const char *anV1 = "v1";
static const std::string anV2 = "v2"; static const char *anV2 = "v2";
static const std::string anV3 = "v3"; static const char *anV3 = "v3";
static const std::string anV4 = "v4"; static const char *anV4 = "v4";
SubMeshXml* submesh = new SubMeshXml(); SubMeshXml* submesh = new SubMeshXml();
@ -635,9 +635,9 @@ void OgreXmlSerializer::ReadBoneAssignments(VertexDataXml *dest)
throw DeadlyImportError("Cannot read bone assignments, vertex data is null."); throw DeadlyImportError("Cannot read bone assignments, vertex data is null.");
} }
static const std::string anVertexIndex = "vertexindex"; static const char *anVertexIndex = "vertexindex";
static const std::string anBoneIndex = "boneindex"; static const char *anBoneIndex = "boneindex";
static const std::string anWeight = "weight"; static const char *anWeight = "weight";
std::set<uint32_t> influencedVertices; std::set<uint32_t> influencedVertices;

View File

@ -98,8 +98,8 @@ private:
void ReadAnimationKeyFrames(Animation *anim, VertexAnimationTrack *dest); void ReadAnimationKeyFrames(Animation *anim, VertexAnimationTrack *dest);
template<typename T> template<typename T>
T ReadAttribute(const std::string &name) const; T ReadAttribute(const char *name) const;
bool HasAttribute(const std::string &name) const; bool HasAttribute(const char *name) const;
std::string &NextNode(); std::string &NextNode();
std::string &SkipCurrentNode(); std::string &SkipCurrentNode();