Fix for deleting still referenced object

ref https://sourceforge.net/p/flightgear/codetickets/2105/

Use the thread safe versions (getRef) of the objectcache methods
This commit is contained in:
Richard Harrison
2019-01-20 18:05:53 +01:00
committed by James Turner
parent ef1cbae22b
commit 8a55c2f44f
5 changed files with 14 additions and 13 deletions

View File

@@ -257,7 +257,8 @@ bool setAttrs(const TexTuple& attrs, Texture* tex,
return false;
osgDB::ReaderWriter::ReadResult result;
result = osgDB::readImageFile(imageName, options);
result = osgDB::readRefImageFile(imageName, options);
osg::ref_ptr<osg::Image> image;
if (result.success())
image = result.getImage();
@@ -590,27 +591,27 @@ Texture* CubeMapBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode*
osg::Image* image = result.getImage();
cubeTexture->setImage(TextureCubeMap::POSITIVE_X, image);
}
result = osgDB::readImageFile(_tuple.get<1>(), options);
result = osgDB::readRefImageFile(_tuple.get<1>(), options);
if(result.success()) {
osg::Image* image = result.getImage();
cubeTexture->setImage(TextureCubeMap::NEGATIVE_X, image);
}
result = osgDB::readImageFile(_tuple.get<2>(), options);
result = osgDB::readRefImageFile(_tuple.get<2>(), options);
if(result.success()) {
osg::Image* image = result.getImage();
cubeTexture->setImage(TextureCubeMap::POSITIVE_Y, image);
}
result = osgDB::readImageFile(_tuple.get<3>(), options);
result = osgDB::readRefImageFile(_tuple.get<3>(), options);
if(result.success()) {
osg::Image* image = result.getImage();
cubeTexture->setImage(TextureCubeMap::NEGATIVE_Y, image);
}
result = osgDB::readImageFile(_tuple.get<4>(), options);
result = osgDB::readRefImageFile(_tuple.get<4>(), options);
if(result.success()) {
osg::Image* image = result.getImage();
cubeTexture->setImage(TextureCubeMap::POSITIVE_Z, image);
}
result = osgDB::readImageFile(_tuple.get<5>(), options);
result = osgDB::readRefImageFile(_tuple.get<5>(), options);
if(result.success()) {
osg::Image* image = result.getImage();
cubeTexture->setImage(TextureCubeMap::NEGATIVE_Z, image);
@@ -634,7 +635,7 @@ Texture* CubeMapBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode*
return cubeTexture.release();
osgDB::ReaderWriter::ReadResult result;
result = osgDB::readImageFile(texname, options);
result = osgDB::readRefImageFile(texname, options);
if(result.success()) {
osg::Image* image = result.getImage();
image->flipVertical(); // Seems like the image coordinates are somewhat funny, flip to get better ones

View File

@@ -227,7 +227,7 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options,
}
else
{
osg::Image* image = osgDB::readImageFile(fullMaskPath, options);
osg::Image* image = osgDB::readRefImageFile(fullMaskPath, options);
if (image && image->valid())
{
Texture2DRef object_mask = new osg::Texture2D;

View File

@@ -335,7 +335,7 @@ sgLoad3DModel_internal(const SGPath& path,
options->setDatabasePath(texturepath.local8BitStr());
osgDB::ReaderWriter::ReadResult modelResult;
modelResult = osgDB::readNodeFile(modelpath.local8BitStr(), options.get());
modelResult = osgDB::readRefNodeFile(modelpath.local8BitStr(), options.get());
if (!modelResult.validNode())
throw sg_io_exception("Failed to load 3D model:" + modelResult.message(),
modelpath);

View File

@@ -43,9 +43,9 @@ SGLoadTexture2D(bool staticTexture, const std::string& path,
{
osg::Image* image;
if (options)
image = osgDB::readImageFile(path, options);
image = osgDB::readRefImageFile(path, options);
else
image = osgDB::readImageFile(path);
image = osgDB::readRefImageFile(path);
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
texture->setImage(image);
if (staticTexture)
@@ -141,7 +141,7 @@ Texture2D* TextureUpdateVisitor::textureReplace(int unit, const StateAttribute*
// If it is empty or they are identical then there is nothing to do
if (fullLiveryFile.empty() || fullLiveryFile == *fullFilePath)
return 0;
Image* newImage = readImageFile(fullLiveryFile);
Image* newImage = readRefImageFile(fullLiveryFile);
if (!newImage)
return 0;
CopyOp copyOp(CopyOp::DEEP_COPY_ALL & ~CopyOp::DEEP_COPY_IMAGES);

View File

@@ -208,7 +208,7 @@ ReaderWriterSPT::readObject(const std::string& fileName, const osgDB::Options* o
imageFileName = osgDB::concatPaths(imageFileName, "Globe");
imageFileName = osgDB::concatPaths(imageFileName, "world.topo.bathy.200407.3x4096x2048.png");
}
if (osg::Image* image = osgDB::readImageFile(imageFileName, options)) {
if (osg::Image* image = osgDB::readRefImageFile(imageFileName, options)) {
osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);
texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT);