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:
committed by
James Turner
parent
ef1cbae22b
commit
8a55c2f44f
@@ -257,7 +257,8 @@ bool setAttrs(const TexTuple& attrs, Texture* tex,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
osgDB::ReaderWriter::ReadResult result;
|
osgDB::ReaderWriter::ReadResult result;
|
||||||
result = osgDB::readImageFile(imageName, options);
|
|
||||||
|
result = osgDB::readRefImageFile(imageName, options);
|
||||||
osg::ref_ptr<osg::Image> image;
|
osg::ref_ptr<osg::Image> image;
|
||||||
if (result.success())
|
if (result.success())
|
||||||
image = result.getImage();
|
image = result.getImage();
|
||||||
@@ -590,27 +591,27 @@ Texture* CubeMapBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode*
|
|||||||
osg::Image* image = result.getImage();
|
osg::Image* image = result.getImage();
|
||||||
cubeTexture->setImage(TextureCubeMap::POSITIVE_X, image);
|
cubeTexture->setImage(TextureCubeMap::POSITIVE_X, image);
|
||||||
}
|
}
|
||||||
result = osgDB::readImageFile(_tuple.get<1>(), options);
|
result = osgDB::readRefImageFile(_tuple.get<1>(), options);
|
||||||
if(result.success()) {
|
if(result.success()) {
|
||||||
osg::Image* image = result.getImage();
|
osg::Image* image = result.getImage();
|
||||||
cubeTexture->setImage(TextureCubeMap::NEGATIVE_X, image);
|
cubeTexture->setImage(TextureCubeMap::NEGATIVE_X, image);
|
||||||
}
|
}
|
||||||
result = osgDB::readImageFile(_tuple.get<2>(), options);
|
result = osgDB::readRefImageFile(_tuple.get<2>(), options);
|
||||||
if(result.success()) {
|
if(result.success()) {
|
||||||
osg::Image* image = result.getImage();
|
osg::Image* image = result.getImage();
|
||||||
cubeTexture->setImage(TextureCubeMap::POSITIVE_Y, image);
|
cubeTexture->setImage(TextureCubeMap::POSITIVE_Y, image);
|
||||||
}
|
}
|
||||||
result = osgDB::readImageFile(_tuple.get<3>(), options);
|
result = osgDB::readRefImageFile(_tuple.get<3>(), options);
|
||||||
if(result.success()) {
|
if(result.success()) {
|
||||||
osg::Image* image = result.getImage();
|
osg::Image* image = result.getImage();
|
||||||
cubeTexture->setImage(TextureCubeMap::NEGATIVE_Y, image);
|
cubeTexture->setImage(TextureCubeMap::NEGATIVE_Y, image);
|
||||||
}
|
}
|
||||||
result = osgDB::readImageFile(_tuple.get<4>(), options);
|
result = osgDB::readRefImageFile(_tuple.get<4>(), options);
|
||||||
if(result.success()) {
|
if(result.success()) {
|
||||||
osg::Image* image = result.getImage();
|
osg::Image* image = result.getImage();
|
||||||
cubeTexture->setImage(TextureCubeMap::POSITIVE_Z, image);
|
cubeTexture->setImage(TextureCubeMap::POSITIVE_Z, image);
|
||||||
}
|
}
|
||||||
result = osgDB::readImageFile(_tuple.get<5>(), options);
|
result = osgDB::readRefImageFile(_tuple.get<5>(), options);
|
||||||
if(result.success()) {
|
if(result.success()) {
|
||||||
osg::Image* image = result.getImage();
|
osg::Image* image = result.getImage();
|
||||||
cubeTexture->setImage(TextureCubeMap::NEGATIVE_Z, image);
|
cubeTexture->setImage(TextureCubeMap::NEGATIVE_Z, image);
|
||||||
@@ -634,7 +635,7 @@ Texture* CubeMapBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode*
|
|||||||
return cubeTexture.release();
|
return cubeTexture.release();
|
||||||
|
|
||||||
osgDB::ReaderWriter::ReadResult result;
|
osgDB::ReaderWriter::ReadResult result;
|
||||||
result = osgDB::readImageFile(texname, options);
|
result = osgDB::readRefImageFile(texname, options);
|
||||||
if(result.success()) {
|
if(result.success()) {
|
||||||
osg::Image* image = result.getImage();
|
osg::Image* image = result.getImage();
|
||||||
image->flipVertical(); // Seems like the image coordinates are somewhat funny, flip to get better ones
|
image->flipVertical(); // Seems like the image coordinates are somewhat funny, flip to get better ones
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
osg::Image* image = osgDB::readImageFile(fullMaskPath, options);
|
osg::Image* image = osgDB::readRefImageFile(fullMaskPath, options);
|
||||||
if (image && image->valid())
|
if (image && image->valid())
|
||||||
{
|
{
|
||||||
Texture2DRef object_mask = new osg::Texture2D;
|
Texture2DRef object_mask = new osg::Texture2D;
|
||||||
|
|||||||
@@ -335,7 +335,7 @@ sgLoad3DModel_internal(const SGPath& path,
|
|||||||
|
|
||||||
options->setDatabasePath(texturepath.local8BitStr());
|
options->setDatabasePath(texturepath.local8BitStr());
|
||||||
osgDB::ReaderWriter::ReadResult modelResult;
|
osgDB::ReaderWriter::ReadResult modelResult;
|
||||||
modelResult = osgDB::readNodeFile(modelpath.local8BitStr(), options.get());
|
modelResult = osgDB::readRefNodeFile(modelpath.local8BitStr(), options.get());
|
||||||
if (!modelResult.validNode())
|
if (!modelResult.validNode())
|
||||||
throw sg_io_exception("Failed to load 3D model:" + modelResult.message(),
|
throw sg_io_exception("Failed to load 3D model:" + modelResult.message(),
|
||||||
modelpath);
|
modelpath);
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ SGLoadTexture2D(bool staticTexture, const std::string& path,
|
|||||||
{
|
{
|
||||||
osg::Image* image;
|
osg::Image* image;
|
||||||
if (options)
|
if (options)
|
||||||
image = osgDB::readImageFile(path, options);
|
image = osgDB::readRefImageFile(path, options);
|
||||||
else
|
else
|
||||||
image = osgDB::readImageFile(path);
|
image = osgDB::readRefImageFile(path);
|
||||||
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
|
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
|
||||||
texture->setImage(image);
|
texture->setImage(image);
|
||||||
if (staticTexture)
|
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 it is empty or they are identical then there is nothing to do
|
||||||
if (fullLiveryFile.empty() || fullLiveryFile == *fullFilePath)
|
if (fullLiveryFile.empty() || fullLiveryFile == *fullFilePath)
|
||||||
return 0;
|
return 0;
|
||||||
Image* newImage = readImageFile(fullLiveryFile);
|
Image* newImage = readRefImageFile(fullLiveryFile);
|
||||||
if (!newImage)
|
if (!newImage)
|
||||||
return 0;
|
return 0;
|
||||||
CopyOp copyOp(CopyOp::DEEP_COPY_ALL & ~CopyOp::DEEP_COPY_IMAGES);
|
CopyOp copyOp(CopyOp::DEEP_COPY_ALL & ~CopyOp::DEEP_COPY_IMAGES);
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ ReaderWriterSPT::readObject(const std::string& fileName, const osgDB::Options* o
|
|||||||
imageFileName = osgDB::concatPaths(imageFileName, "Globe");
|
imageFileName = osgDB::concatPaths(imageFileName, "Globe");
|
||||||
imageFileName = osgDB::concatPaths(imageFileName, "world.topo.bathy.200407.3x4096x2048.png");
|
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;
|
osg::Texture2D* texture = new osg::Texture2D;
|
||||||
texture->setImage(image);
|
texture->setImage(image);
|
||||||
texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT);
|
texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT);
|
||||||
|
|||||||
Reference in New Issue
Block a user