From 4521d3987cbaeba6be7d16ab93e5b24b9538f1e4 Mon Sep 17 00:00:00 2001 From: Alexei Dobrohotov Date: Fri, 28 Jan 2022 01:15:15 +0300 Subject: [PATCH] Fix out of bounds UV set handling --- components/nifosg/nifloader.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 67cb16b795..36f474a223 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -1136,18 +1136,18 @@ namespace NifOsg const auto& uvlist = data->uvlist; int textureStage = 0; - for (const unsigned int uvSet : boundTextures) + for (std::vector::const_iterator it = boundTextures.begin(); it != boundTextures.end(); ++it, ++textureStage) { + unsigned int uvSet = *it; if (uvSet >= uvlist.size()) { Log(Debug::Verbose) << "Out of bounds UV set " << uvSet << " on shape \"" << name << "\" in " << mFilename; - if (!uvlist.empty()) - geometry->setTexCoordArray(textureStage, new osg::Vec2Array(uvlist[0].size(), uvlist[0].data()), osg::Array::BIND_PER_VERTEX); - continue; + if (uvlist.empty()) + continue; + uvSet = 0; } geometry->setTexCoordArray(textureStage, new osg::Vec2Array(uvlist[uvSet].size(), uvlist[uvSet].data()), osg::Array::BIND_PER_VERTEX); - textureStage++; } }