From 2599aba19625074c7c03fb8a13f660d56803e7bd Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 8 Jul 2018 20:36:04 +0300 Subject: [PATCH] Fix check whether file name starts with x or X If path doens't contains / or \, then slashpos will be 0. Therefore slashpos + 1 = 1 doesn't point to first symbol. xmesh.nif ^ slashpos + 1 --- components/nifbullet/bulletnifloader.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/components/nifbullet/bulletnifloader.cpp b/components/nifbullet/bulletnifloader.cpp index 8f827e4e2..a7afabf8f 100644 --- a/components/nifbullet/bulletnifloader.cpp +++ b/components/nifbullet/bulletnifloader.cpp @@ -88,18 +88,13 @@ osg::ref_ptr BulletNifLoader::load(const Nif::NIFFilePtr& else { bool autogenerated = hasAutoGeneratedCollision(node); - bool isAnimated = false; // files with the name convention xmodel.nif usually have keyframes stored in a separate file xmodel.kf (see Animation::addAnimSource). // assume all nodes in the file will be animated std::string filename = nif->getFilename(); - size_t slashpos = filename.find_last_of("/\\"); - if (slashpos == std::string::npos) - slashpos = 0; - if (slashpos+1 < filename.size() && (filename[slashpos+1] == 'x' || filename[slashpos+1] == 'X')) - { - isAnimated = true; - } + const std::size_t slashpos = filename.find_last_of("/\\"); + const std::size_t letterPos = slashpos == std::string::npos ? 0 : slashpos + 1; + const bool isAnimated = letterPos < filename.size() && (filename[letterPos] == 'x' || filename[letterPos] == 'X'); handleNode(node, 0, autogenerated, isAnimated, autogenerated);