[osg-users] Texture Caching Problem with 3.6.3/4
Greg D
g.danaha at networkharbor.com
Mon Dec 9 09:48:48 PST 2019
Robert,
Thanks for the information. I cleaned up the references to allow smart
pointers to work for the model and viewer as intended. The explicit
deletion and cleanup code was added years ago in an attempt to address a
memory leak issue. Unfortunately osgDB::readRefFile() wasn't available
when the original code was written years ago, and the loading code was
taken directly the first sample that loaded a model file -
osganimationhardware. We've never had an issue but I did make the changes
you suggested.
After the changes I found the problem persisted. It ended up being a
change to the OpenFlight plugin. The older version had its own caches for
textures and external references (3.4.0). The newer version (3.6.3/4) uses
the osgDB ObjectCache class. The problem with that is Texture2D.cpp
deletes the texture image data on the first render (line 285) so the cached
data is null right after the file is loaded, thus the black textures. In
reality, the osgDB cache is useless since (at least) the texture data is
overwritten almost immediately. I found that after the cache expiration
timed out all the cached data was deleted and the model will load correctly
since it is not getting corrupted data from the cache but loading the files.
Will there be a fix coming for the cache issue or should I do a workaround
(perhaps re-using the 3.4.0 OpenFlight cache code)?
Thanks.
On Friday, December 6, 2019 at 1:35:45 PM UTC-6, Greg D wrote:
>
> I have been using OSG for a number of years for a commercial product. Our
> product loads various models and earth views as the user requires them (for
> security monitoring – buildings and campuses mostly). I have a problem
> with 3.6.3/4 that wasn't there in 3.4.0.
>
>
>
> I have an OpenFlight model (sample/demo model) that uses textures for
> terrain and on buildings. The first time I load it all is fine. However,
> if I load another model (or another graphics file – the application
> supports AutoCAD, raster, OSG Earth, and ArcGIS formats as well) then
> reload the model the terrain is black and the textures are corrupted if
> they are not black. This worked fine with 3.4.0 and 3.4.1 but does not
> work with 3.6.3 or 3.6.4.
>
>
>
> I have debugged into the code and it appears that the model and textures
> are always reloaded from the cache and I cannot override this (setting
> Options::CACHE_NONE doesn’t affect it - in 3.4.0 the model always loaded
> from files with Options set to CACHE_NONE). If I look at the model graph
> in memory (after the first load), the textures appear to be erased or
> over-written during the traversals in one of the classes called in
> ViewerBase::runOperations() (though it’s a little confusing to me at that
> point, it appears to be when GlobalObjectVisitor::compile() calls
> node.accept(*this)). During the traversals where the textures appear to be
> over-written, I noticed the context ID is always 0, so the textures appear
> to be reloaded, over-writing the original data in the process (though I
> could be quite confused as to what I am seeing and it may all be irrelevant
> to the issue).
>
>
> Below is a short snippet from my initialization and cleanup code between
> model loads. I load the model, add a clip node to peel down through the
> models vertically. I also add other nodes to hold embedded bitmaps
> (Billboards) representing security devices – cameras, doors, alarm points,
> etc. Those details are omitted from the code below. After the model is
> loaded I set up the graphics context and render the image to an offscreen
> window (which is then copied to a memory bitmap). The application is a
> Windows console app (with hidden window) that streams bitmap images to the
> client app via named pipe on the same machine (I know, it’s complicated,
> but it’s a complex environment, including live video windows).
>
>
>
> As I said, it has worked fine with previous versions of OSG (back to
> 3.0.1, if not earlier). This may be specific to Open Flight models, as I
> can load FBX models, OSG earth files, or the cessnafire.osg model and the
> textures appear correct.
>
>
> Any help would be appreciated. If the model would always be loaded from
> the file when Options::CACHE_NONE were set it would solve my problem.
>
>
> OSGLoadResult OpenSceneGraphBitmap::LoadModel(std::string fileName,
> osgDB::Options* dbOptions)
>
> {
>
> CleanupModel();
>
>
>
> if (m_Root == nullptr)
>
> m_Root = new osg::Group; // Init the main Root
> Node/Group
>
>
>
> // Load the Model from the model name
>
> osg::Group* model = dynamic_cast<osg::Group*>(osgDB::readNodeFile(
> fileName, dbOptions));
>
> if (model != nullptr)
>
> {
>
> // Optimize the model
>
> osgUtil::Optimizer optimizer;
>
> optimizer.optimize(model);
>
> optimizer.reset();
>
>
>
> // Create the clip node and add to scene
>
> osg::ComputeBoundsVisitor cbbv;
>
> model->accept(cbbv);
>
> osg::BoundingBox bb = cbbv.getBoundingBox();
>
>
>
> osg::ref_ptr<osg::ClipPlane> clipPlane = new osg::ClipPlane;
>
> clipPlane->setClipPlane(0.0, 0.0, -1.0, bb.zMin() +
> (bb.zMax() - bb.zMin()));
>
> clipPlane->setClipPlaneNum(0);
>
>
>
> osg::ref_ptr<osg::ClipNode> clipNode = new osg::ClipNode;
>
> clipNode->setName("CLIP_NODE");
>
> clipNode->addClipPlane(clipPlane.get());
>
>
>
> clipNode->setCullingActive(false);
>
>
>
> model->setStateSet(clipNode->getStateSet());
>
>
>
> m_Root->addChild(clipNode);
>
>
>
> m_Root->addChild(model);
>
>
>
> m_Root->setDataVariance(osg::Object::DYNAMIC);
>
>
>
>
>
> return OSGLoadResult::Sucess;
>
> }
>
>
>
> // since load failed, reset the wait event so the render thread
> resumes
>
> return OSGLoadResult::FileLoadError;
>
> }
>
>
>
> void OpenSceneGraphBitmap::CleanupModel()
>
> {
>
> RemoveViews();
>
>
>
> if (m_Root != nullptr) // if root already exists (already
> loaded previous scene) remove children to clean up
>
> {
>
> m_Root->releaseGLObjects();
>
> m_Root->removeChildren(0, m_Root->getNumChildren());
>
>
>
> void* ptr = m_Root.release();
>
> delete ptr;
>
> m_Root = nullptr;
>
> }
>
> }
>
>
>
> void OpenSceneGraphBitmap::RemoveViews()
>
> {
>
> if (m_nhiCompositeViewer != nullptr)
>
> {
>
> m_nhiCompositeViewer->setDone(true);
>
>
>
> delete m_nhiCompositeViewer;
>
> m_nhiCompositeViewer = nullptr;
>
> }
>
> }
>
>
>
--
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+unsubscribe at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/8ab9bfc5-c4c2-4787-bb53-a60d39bd47b2%40googlegroups.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20191209/649aa4c6/attachment.html>
More information about the osg-users
mailing list