From 966789de9059e130ef7e0ce943d886dbe53df259 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 13 Mar 2014 22:16:00 +0000 Subject: [PATCH] Fix leak of object-mask textures --- simgear/scene/material/mat.cxx | 4 ++-- simgear/scene/material/mat.hxx | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/simgear/scene/material/mat.cxx b/simgear/scene/material/mat.cxx index 738dd5d0..2fe25104 100644 --- a/simgear/scene/material/mat.cxx +++ b/simgear/scene/material/mat.cxx @@ -237,7 +237,7 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options, osg::Image* image = osgDB::readImageFile(fullMaskPath, options); if (image && image->valid()) { - osg::Texture2D* object_mask = new osg::Texture2D; + Texture2DRef object_mask = new osg::Texture2D; bool dds_mask = (ompath.lower_extension() == "dds"); @@ -485,7 +485,7 @@ osg::Texture2D* SGMaterial::get_object_mask(const SGTexturedTriangleBin& triangl // so we index based on the texture index, unsigned int i = triangleBin.getTextureIndex() % _status.size(); if (i < _masks.size()) { - return _masks[i]; + return _masks[i].get(); } else { return 0; } diff --git a/simgear/scene/material/mat.hxx b/simgear/scene/material/mat.hxx index 7ed5958c..c0a65132 100644 --- a/simgear/scene/material/mat.hxx +++ b/simgear/scene/material/mat.hxx @@ -42,6 +42,9 @@ namespace osg class StateSet; } + +typedef osg::ref_ptr Texture2DRef; + #include #include // for SGMutex #include @@ -466,7 +469,7 @@ private: // Object mask, a simple RGB texture used as a mask when placing // random vegetation, objects and buildings - std::vector _masks; + std::vector _masks; // Condition, indicating when this material is active SGSharedPtr condition; -- 2.39.5