OSG < 3.4.x fixes
This will use the inherently unsafe versions of the load methods which can result in deleting an object (from the cache) that has just been loaded in the database thread. Symptom OSG WARN deleting still referenced object.
This commit is contained in:
parent
30482a3599
commit
b76f78c6da
@ -275,7 +275,11 @@ bool setAttrs(const TexTuple& attrs, Texture* tex,
|
||||
options->setLoadOriginHint(SGReaderWriterOptions::LoadOriginHint::ORIGIN_EFFECTS_NORMALIZED);
|
||||
else
|
||||
options->setLoadOriginHint(SGReaderWriterOptions::LoadOriginHint::ORIGIN_EFFECTS);
|
||||
#if OSG_VERSION_LESS_THAN(3,4,2)
|
||||
result = osgDB::readImageFile(imageName, options);
|
||||
#else
|
||||
result = osgDB::readRefImageFile(imageName, options);
|
||||
#endif
|
||||
options->setLoadOriginHint(origLOH);
|
||||
osg::ref_ptr<osg::Image> image;
|
||||
if (result.success())
|
||||
@ -607,32 +611,56 @@ Texture* CubeMapBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode*
|
||||
SGReaderWriterOptions* wOpts = (SGReaderWriterOptions*)options;
|
||||
SGReaderWriterOptions::LoadOriginHint origLOH = wOpts->getLoadOriginHint();
|
||||
wOpts->setLoadOriginHint(SGReaderWriterOptions::LoadOriginHint::ORIGIN_EFFECTS);
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
result = osgDB::readImageFile(_tuple.get<0>(), options);
|
||||
#else
|
||||
result = osgDB::readRefImageFile(_tuple.get<0>(), options);
|
||||
#endif
|
||||
if(result.success()) {
|
||||
osg::Image* image = result.getImage();
|
||||
cubeTexture->setImage(TextureCubeMap::POSITIVE_X, image);
|
||||
}
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
result = osgDB::readImageFile(_tuple.get<1>(), options);
|
||||
#else
|
||||
result = osgDB::readRefImageFile(_tuple.get<1>(), options);
|
||||
#endif
|
||||
if(result.success()) {
|
||||
osg::Image* image = result.getImage();
|
||||
cubeTexture->setImage(TextureCubeMap::NEGATIVE_X, image);
|
||||
}
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
result = osgDB::readImageFile(_tuple.get<2>(), options);
|
||||
#else
|
||||
result = osgDB::readRefImageFile(_tuple.get<2>(), options);
|
||||
#endif
|
||||
if(result.success()) {
|
||||
osg::Image* image = result.getImage();
|
||||
cubeTexture->setImage(TextureCubeMap::POSITIVE_Y, image);
|
||||
}
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
result = osgDB::readImageFile(_tuple.get<3>(), options);
|
||||
#else
|
||||
result = osgDB::readRefImageFile(_tuple.get<3>(), options);
|
||||
#endif
|
||||
if(result.success()) {
|
||||
osg::Image* image = result.getImage();
|
||||
cubeTexture->setImage(TextureCubeMap::NEGATIVE_Y, image);
|
||||
}
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
result = osgDB::readImageFile(_tuple.get<4>(), options);
|
||||
#else
|
||||
result = osgDB::readRefImageFile(_tuple.get<4>(), options);
|
||||
#endif
|
||||
if(result.success()) {
|
||||
osg::Image* image = result.getImage();
|
||||
cubeTexture->setImage(TextureCubeMap::POSITIVE_Z, image);
|
||||
}
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
result = osgDB::readImageFile(_tuple.get<5>(), options);
|
||||
#else
|
||||
result = osgDB::readRefImageFile(_tuple.get<5>(), options);
|
||||
#endif
|
||||
if(result.success()) {
|
||||
osg::Image* image = result.getImage();
|
||||
cubeTexture->setImage(TextureCubeMap::NEGATIVE_Z, image);
|
||||
@ -657,7 +685,11 @@ Texture* CubeMapBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode*
|
||||
return cubeTexture.release();
|
||||
|
||||
osgDB::ReaderWriter::ReadResult result;
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
result = osgDB::readImageFile(texname, options);
|
||||
#else
|
||||
result = osgDB::readRefImageFile(texname, options);
|
||||
#endif
|
||||
if(result.success()) {
|
||||
osg::Image* image = result.getImage();
|
||||
image->flipVertical(); // Seems like the image coordinates are somewhat funny, flip to get better ones
|
||||
|
@ -227,7 +227,11 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options,
|
||||
}
|
||||
else
|
||||
{
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
osg::Image* image = osgDB::readImageFile(fullMaskPath, options);
|
||||
#else
|
||||
osg::Image* image = osgDB::readRefImageFile(fullMaskPath, options);
|
||||
#endif
|
||||
if (image && image->valid())
|
||||
{
|
||||
Texture2DRef object_mask = new osg::Texture2D;
|
||||
|
@ -215,7 +215,11 @@ public:
|
||||
if (pagedLOD.getMinRange(i) <= 0) {
|
||||
osg::ref_ptr<const osgDB::Options> options;
|
||||
options = getOptions(pagedLOD.getDatabaseOptions(), pagedLOD.getDatabasePath());
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
node = osgDB::readNodeFile(pagedLOD.getFileName(i), options.get());
|
||||
#else
|
||||
node = osgDB::readRefNodeFile(pagedLOD.getFileName(i), options.get());
|
||||
#endif
|
||||
}
|
||||
if (!node.valid())
|
||||
node = new osg::Group;
|
||||
@ -256,7 +260,11 @@ public:
|
||||
osg::ref_ptr<const osgDB::Options> options;
|
||||
options = getOptions(proxyNode.getDatabaseOptions(), proxyNode.getDatabasePath());
|
||||
osg::ref_ptr<osg::Node> node;
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
node = osgDB::readNodeFile(proxyNode.getFileName(i), options.get());
|
||||
#else
|
||||
node = osgDB::readRefNodeFile(proxyNode.getFileName(i), options.get());
|
||||
#endif
|
||||
if (!node.valid())
|
||||
node = new osg::Group;
|
||||
if (i < proxyNode.getNumChildren())
|
||||
@ -353,7 +361,11 @@ SGSharedPtr<BVHNode>
|
||||
BVHPageNodeOSG::load(const std::string& name, const osg::ref_ptr<const osg::Referenced>& options)
|
||||
{
|
||||
osg::ref_ptr<osg::Node> node;
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
node = osgDB::readNodeFile(name, dynamic_cast<const osgDB::Options*>(options.get()));
|
||||
#else
|
||||
node = osgDB::readRefNodeFile(name, dynamic_cast<const osgDB::Options*>(options.get()));
|
||||
#endif
|
||||
if (!node.valid())
|
||||
return SGSharedPtr<BVHNode>();
|
||||
|
||||
|
@ -338,7 +338,11 @@ sgLoad3DModel_internal(const SGPath& path,
|
||||
|
||||
options->setDatabasePath(texturepath.local8BitStr());
|
||||
osgDB::ReaderWriter::ReadResult modelResult;
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
modelResult = osgDB::readNodeFile(modelpath.local8BitStr(), options.get());
|
||||
#else
|
||||
modelResult = osgDB::readRefNodeFile(modelpath.local8BitStr(), options.get());
|
||||
#endif
|
||||
if (!modelResult.validNode())
|
||||
throw sg_io_exception("Failed to load 3D model:" + modelResult.message(),
|
||||
modelpath);
|
||||
|
@ -43,9 +43,18 @@ SGLoadTexture2D(bool staticTexture, const std::string& path,
|
||||
{
|
||||
osg::Image* image;
|
||||
if (options)
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
image = osgDB::readImageFile(path, options);
|
||||
#else
|
||||
image = osgDB::readRefImageFile(path, options);
|
||||
#endif
|
||||
else
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
image = osgDB::readImageFile(path);
|
||||
#else
|
||||
image = osgDB::readRefImageFile(path);
|
||||
#endif
|
||||
|
||||
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
|
||||
texture->setImage(image);
|
||||
if (staticTexture)
|
||||
@ -141,7 +150,11 @@ 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;
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
Image* newImage = readImageFile(fullLiveryFile);
|
||||
#else
|
||||
Image* newImage = readRefImageFile(fullLiveryFile);
|
||||
#endif
|
||||
if (!newImage)
|
||||
return 0;
|
||||
CopyOp copyOp(CopyOp::DEEP_COPY_ALL & ~CopyOp::DEEP_COPY_IMAGES);
|
||||
|
@ -101,7 +101,11 @@ osg::Node* loadFile(const string& path, SGReaderWriterOptions* options)
|
||||
options->setInstantiateEffects(true);
|
||||
}
|
||||
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
ref_ptr<Node> model = readNodeFile(path, options);
|
||||
#else
|
||||
ref_ptr<Node> model = readRefNodeFile(path, options);
|
||||
#endif
|
||||
if (!model)
|
||||
return 0;
|
||||
else
|
||||
|
@ -208,7 +208,11 @@ 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_VERSION_LESS_THAN(3,4,0)
|
||||
if (osg::Image* image = osgDB::readImageFile(imageFileName, options)) {
|
||||
#else
|
||||
if (osg::Image* image = osgDB::readRefImageFile(imageFileName, options)) {
|
||||
#endif
|
||||
osg::Texture2D* texture = new osg::Texture2D;
|
||||
texture->setImage(image);
|
||||
texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT);
|
||||
@ -256,7 +260,11 @@ ReaderWriterSPT::createTree(const BucketBox& bucketBox, const LocalOptions& opti
|
||||
if (bucketBox.getIsBucketSize()) {
|
||||
std::string fileName;
|
||||
fileName = bucketBox.getBucket().gen_index_str() + std::string(".stg");
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
return osgDB::readNodeFile(fileName, options._options);
|
||||
#else
|
||||
return osgDB::readRefNodeFile(fileName, options._options);
|
||||
#endif
|
||||
} else if (!topLevel && options.isPageLevel(bucketBox.getStartLevel())) {
|
||||
return createPagedLOD(bucketBox, options);
|
||||
} else {
|
||||
@ -314,7 +322,11 @@ ReaderWriterSPT::createPagedLOD(const BucketBox& bucketBox, const LocalOptions&
|
||||
std::string fileName = osgDB::findDataFile(lodPath + extensions[i], options._options);
|
||||
if (fileName.empty())
|
||||
continue;
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(fileName, options._options);
|
||||
#else
|
||||
osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFile(fileName, options._options);
|
||||
#endif
|
||||
if (!node.valid())
|
||||
continue;
|
||||
pagedLOD->addChild(node.get(), range, std::numeric_limits<float>::max());
|
||||
@ -412,7 +424,11 @@ ReaderWriterSPT::getLowLODStateSet(const LocalOptions& options) const
|
||||
localOptions = static_cast<osgDB::Options*>(options._options->clone(osg::CopyOp()));
|
||||
localOptions->setObjectCacheHint(osgDB::Options::CACHE_ALL);
|
||||
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
osg::ref_ptr<osg::Object> object = osgDB::readObjectFile("state.spt", localOptions.get());
|
||||
#else
|
||||
osg::ref_ptr<osg::Object> object = osgDB::readRefObjectFile("state.spt", localOptions.get());
|
||||
#endif
|
||||
if (!dynamic_cast<osg::StateSet*>(object.get()))
|
||||
return 0;
|
||||
|
||||
|
@ -156,7 +156,11 @@ struct ReaderWriterSTG::_ModelBin {
|
||||
proxy->setCenterMode(osg::ProxyNode::UNION_OF_BOUNDING_SPHERE_AND_USER_DEFINED);
|
||||
node = proxy;
|
||||
} else {
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
node = osgDB::readNodeFile(o._name, o._options.get());
|
||||
#else
|
||||
node = osgDB::readRefNodeFile(o._name, o._options.get());
|
||||
#endif
|
||||
if (!node.valid()) {
|
||||
SG_LOG(SG_TERRAIN, SG_ALERT, o._errorLocation << ": Failed to load "
|
||||
<< o._token << " '" << o._name << "'");
|
||||
@ -553,7 +557,11 @@ struct ReaderWriterSTG::_ModelBin {
|
||||
if (_foundBase) {
|
||||
for (auto stgObject : _objectList) {
|
||||
osg::ref_ptr<osg::Node> node;
|
||||
#if OSG_VERSION_LESS_THAN(3,4,0)
|
||||
node = osgDB::readNodeFile(stgObject._name, stgObject._options.get());
|
||||
#else
|
||||
node = osgDB::readRefNodeFile(stgObject._name, stgObject._options.get());
|
||||
#endif
|
||||
if (!node.valid()) {
|
||||
SG_LOG(SG_TERRAIN, SG_ALERT, stgObject._errorLocation << ": Failed to load "
|
||||
<< stgObject._token << " '" << stgObject._name << "'");
|
||||
|
Loading…
Reference in New Issue
Block a user