Partial fix for reset when using --composite-viewer=1.
[Marked as 'Partial' because, for me, reset eventually runs out of memory with both composite-viewer and non-composite-viewer.] fgStartNewReset(): pass existing composite_viewer to FGRenderer constructor so that it is used after reset instead of us creating a new instance. Also reuse existing osgViewer::View. In FGRenderer::init(), don't create new osgViewer::CompositeViewer if this->composite_viewer is already set.
This commit is contained in:
parent
42eacf6928
commit
c031abe8d2
3 changed files with 59 additions and 10 deletions
|
@ -1288,7 +1288,13 @@ void fgStartNewReset()
|
|||
FGRenderer* render = globals->get_renderer();
|
||||
// needed or we crash in multi-threaded OSG mode
|
||||
render->getViewerBase()->stopThreading();
|
||||
|
||||
|
||||
osg::ref_ptr<osgViewer::CompositeViewer> composite_viewer = render->getCompositeViewer();
|
||||
osg::ref_ptr<osgViewer::View> composite_viewer_view;
|
||||
if (composite_viewer) {
|
||||
composite_viewer_view = render->getView();
|
||||
}
|
||||
|
||||
// order is important here since tile-manager shutdown needs to
|
||||
// access the scenery object
|
||||
subsystemManger->remove(FGScenery::staticSubsystemClassId());
|
||||
|
@ -1375,21 +1381,39 @@ void fgStartNewReset()
|
|||
fgInitAircraftPaths(true);
|
||||
fgInitAircraft(true);
|
||||
|
||||
render = new FGRenderer;
|
||||
render = new FGRenderer(composite_viewer);
|
||||
render->setEventHandler(eventHandler);
|
||||
eventHandler->reset();
|
||||
globals->set_renderer(render);
|
||||
render->init();
|
||||
render->setView(viewer.get());
|
||||
|
||||
if (composite_viewer) {
|
||||
render->setView(composite_viewer_view);
|
||||
}
|
||||
else {
|
||||
render->setView(viewer.get());
|
||||
}
|
||||
|
||||
sgUserDataInit( globals->get_props() );
|
||||
|
||||
viewer->getDatabasePager()->setUpThreads(20, 1);
|
||||
|
||||
// must do this before preinit for Rembrandthe
|
||||
flightgear::CameraGroup::buildDefaultGroup(viewer.get());
|
||||
render->preinit();
|
||||
viewer->startThreading();
|
||||
if (composite_viewer) {
|
||||
composite_viewer_view->getDatabasePager()->setUpThreads(20, 1);
|
||||
flightgear::CameraGroup::buildDefaultGroup(composite_viewer_view);
|
||||
composite_viewer_view->setFrameStamp(composite_viewer->getFrameStamp());
|
||||
composite_viewer_view->setDatabasePager(FGScenery::getPagerSingleton());
|
||||
composite_viewer_view->getDatabasePager()->setUnrefImageDataAfterApplyPolicy(true, false);
|
||||
osg::GraphicsContext::createNewContextID();
|
||||
render->setView(composite_viewer_view);
|
||||
render->preinit();
|
||||
composite_viewer->startThreading();
|
||||
}
|
||||
else {
|
||||
viewer->getDatabasePager()->setUpThreads(20, 1);
|
||||
// must do this before preinit for Rembrandthe
|
||||
flightgear::CameraGroup::buildDefaultGroup(viewer.get());
|
||||
render->preinit();
|
||||
viewer->startThreading();
|
||||
}
|
||||
|
||||
fgOSResetProperties();
|
||||
|
||||
|
|
|
@ -351,6 +351,17 @@ FGRenderer::FGRenderer() :
|
|||
_updateVisitor = new SGUpdateVisitor;
|
||||
}
|
||||
|
||||
FGRenderer::FGRenderer(osg::ref_ptr<osgViewer::CompositeViewer> composite_viewer) :
|
||||
composite_viewer(composite_viewer),
|
||||
_sky(NULL),
|
||||
MaximumTextureSize(0)
|
||||
{
|
||||
_root = new osg::Group;
|
||||
_root->setName("fakeRoot");
|
||||
_updateVisitor = new SGUpdateVisitor;
|
||||
}
|
||||
|
||||
|
||||
FGRenderer::~FGRenderer()
|
||||
{
|
||||
SGPropertyChangeListenerVec::iterator i = _listeners.begin();
|
||||
|
@ -462,7 +473,12 @@ FGRenderer::init( void )
|
|||
}
|
||||
composite_viewer_enabled = 1;
|
||||
SG_LOG(SG_VIEW, SG_ALERT, "Creating osgViewer::CompositeViewer");
|
||||
composite_viewer = new osgViewer::CompositeViewer;
|
||||
if (composite_viewer) {
|
||||
// reinit.
|
||||
}
|
||||
else {
|
||||
composite_viewer = new osgViewer::CompositeViewer;
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/15207076/openscenegraph-and-multiple-viewers
|
||||
composite_viewer->setReleaseContextAtEndOfFrameHint(false);
|
||||
|
@ -1016,6 +1032,11 @@ osgViewer::ViewerBase* FGRenderer::getViewerBase()
|
|||
}
|
||||
}
|
||||
|
||||
osg::ref_ptr<osgViewer::CompositeViewer> FGRenderer::getCompositeViewer()
|
||||
{
|
||||
return composite_viewer;
|
||||
}
|
||||
|
||||
osgViewer::View* FGRenderer::getView()
|
||||
{
|
||||
/* Would like to assert that FGRenderer::init() has always been called
|
||||
|
|
|
@ -50,6 +50,7 @@ class FGRenderer {
|
|||
public:
|
||||
|
||||
FGRenderer();
|
||||
FGRenderer(osg::ref_ptr<osgViewer::CompositeViewer> composite_viewer);
|
||||
~FGRenderer();
|
||||
|
||||
void preinit();
|
||||
|
@ -67,6 +68,9 @@ public:
|
|||
|
||||
/* Returns either composite_viewer or viewer. */
|
||||
osgViewer::ViewerBase* getViewerBase();
|
||||
|
||||
/** For handling reset. */
|
||||
osg::ref_ptr<osgViewer::CompositeViewer> getCompositeViewer();
|
||||
|
||||
/** Get and set the OSG Viewer object, if any.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue