diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index ad3ba12070..59fc8a577a 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -1027,7 +1027,7 @@ namespace NifOsg } osg::ref_ptr attachTexture(const std::string& name, osg::ref_ptr image, bool wrapS, - bool wrapT, unsigned int uvSet, osg::StateSet* stateset, std::vector& boundTextures) const + bool wrapT, unsigned int uvSet, osg::StateSet* stateset, std::vector& boundTextures) { osg::ref_ptr texture2d = new osg::Texture2D(image); if (image) @@ -1038,22 +1038,23 @@ namespace NifOsg if (stateset) { stateset->setTextureAttributeAndModes(texUnit, texture2d, osg::StateAttribute::ON); - stateset->setTextureAttributeAndModes( - texUnit, new SceneUtil::TextureType(name), osg::StateAttribute::ON); + osg::ref_ptr textureType = new SceneUtil::TextureType(name); + textureType = shareAttribute(textureType); + stateset->setTextureAttributeAndModes(texUnit, textureType, osg::StateAttribute::ON); } boundTextures.emplace_back(uvSet); return texture2d; } osg::ref_ptr attachExternalTexture(const std::string& name, const std::string& path, bool wrapS, - bool wrapT, unsigned int uvSet, osg::StateSet* stateset, std::vector& boundTextures) const + bool wrapT, unsigned int uvSet, osg::StateSet* stateset, std::vector& boundTextures) { return attachTexture(name, getTextureImage(path), wrapS, wrapT, uvSet, stateset, boundTextures); } osg::ref_ptr attachNiSourceTexture(const std::string& name, const Nif::NiSourceTexture* st, bool wrapS, bool wrapT, unsigned int uvSet, osg::StateSet* stateset, - std::vector& boundTextures) const + std::vector& boundTextures) { return attachTexture(name, handleSourceTexture(st), wrapS, wrapT, uvSet, stateset, boundTextures); }