Skip to content

Commit

Permalink
fixes for shutdown crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
dardok committed Jul 28, 2017
1 parent 3c6008c commit bed209c
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 7 deletions.
9 changes: 8 additions & 1 deletion channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ LBINFO << "<----- Channel::configInit(" << initID << ")" << std::endl;

bool Channel::configExit( )
{
LBINFO << "------ Channel::configExit( )" << std::endl;

cleanup( );

return eq::Channel::configExit( );
Expand Down Expand Up @@ -564,7 +566,7 @@ void Channel::worldPick( const eq::Vector3d& origin,
}
}

void Channel::cleanup( )
void Channel::clearScene( )
{
if( _camera.valid( ))
connectCameraToScene( eq::uint128_t( ));
Expand All @@ -575,6 +577,11 @@ void Channel::cleanup( )
_viewer2d = 0;
}

void Channel::cleanup( )
{

}

void Channel::connectCameraToScene( const eq::uint128_t& id )
{
LB_TS_THREAD( _pipeThread );
Expand Down
3 changes: 3 additions & 0 deletions channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class Channel : public eq::Channel
const eq::Vector3d& direction ) const;

private:
friend class Window;
void clearScene( ); // Must call with GL context (i.e. Window::configExitGL)

void cleanup( );

void connectCameraToScene( const eq::uint128_t& id );
Expand Down
14 changes: 9 additions & 5 deletions config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,17 @@ LBINFO << "-----> Config::exit( )" << std::endl;
_viewer->shutdown( );
_pager->cancel( );

// Clear scene graph before GL shutdown
_scene->removeChildren( 0, _scene->getNumChildren( ));

// Clear view references before GL shutdown
{
ViewCollector m( this, true );
accept( m );
}

cleanup( );

// Shutdown GL (destroys View, Channel, Window, Pipe, Node - basically everything)
bool ret = eq::Config::exit( );

cleanup( );

LBINFO << "<----- Config::exit( ) = " << ret << std::endl;
return ret;
}
Expand Down Expand Up @@ -853,6 +850,13 @@ static const char *zshaderFragSource = {
return _scene.get( );
}

void Config::clearScene( )
{
if( _scene.valid( ))
_scene->removeChildren( 0, _scene->getNumChildren( ));
//_scene->removeChild( osgEarth::findTopMostNodeOfType< osgEarth::Util::SkyNode >( _scene ));
}

void Config::cleanup( )
{
deregisterObject( &_initData );
Expand Down
3 changes: 3 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class Config : public eq::Config
private:
osg::Group* getScene( const eq::uint128_t& sceneID, osgViewer::View* view );

friend class Window;
void clearScene( ); // Must call with GL context (i.e. Window::configExitGL)

void cleanup( );

protected:
Expand Down
2 changes: 2 additions & 0 deletions node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ LBINFO << "<----- Node::configInit(" << initID << ")" << std::endl;

bool Node::configExit( )
{
LBINFO << "------ Node::configExit( )" << std::endl;

cleanup( );

return eq::Node::configExit( );
Expand Down
6 changes: 6 additions & 0 deletions pipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace eqEarth
{
// ----------------------------------------------------------------------------

lunchbox::Lock Pipe::_pipeLock;

Pipe::Pipe( eq::Node* parent )
: eq::Pipe( parent )
{
Expand Down Expand Up @@ -43,6 +45,10 @@ LBINFO << "<----- Pipe::configInit(" << initID << ")" << std::endl;

bool Pipe::configExit( )
{
LBINFO << "------ Pipe::configExit( )" << std::endl;

lunchbox::ScopedWrite _mutex( Pipe::getPipeLock( ));

cleanup( );

return eq::Pipe::configExit( );
Expand Down
4 changes: 4 additions & 0 deletions pipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Pipe : public eq::Pipe
public:
Pipe( eq::Node* parent );

static lunchbox::Lock *getPipeLock( ) { return &_pipeLock; };

protected:
virtual ~Pipe( );

Expand All @@ -25,5 +27,7 @@ class Pipe : public eq::Pipe

private:
void cleanup( );

static lunchbox::Lock _pipeLock;
};
}
20 changes: 19 additions & 1 deletion window.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "channel.h"
#include "window.h"
#include "pipe.h"
#include "node.h"
#include "config.h"

#include <osgEarth/Registry>

Expand Down Expand Up @@ -164,6 +167,8 @@ bool Window::configExitGL( )
{
LBINFO << "------ Window::configExitGL( )" << std::endl;

lunchbox::ScopedWrite _mutex( Pipe::getPipeLock( ));

cleanup( );

return eq::Window::configExitGL( );
Expand Down Expand Up @@ -227,13 +232,26 @@ void Window::swapBuffers( )
eq::Window::swapBuffers( );
}

struct Window::ClearChannels : public eq::ConfigVisitor
{
virtual eq::VisitorResult visit( eq::Channel* channel )
{
static_cast< Channel* >( channel )->clearScene( );
}
};

void Window::cleanup( )
{
if( _window.valid( ))
{
ClearChannels c;
accept( c );

static_cast< Config* >( getConfig( ))->clearScene( );

static_cast< Node* >( getNode( ))->removeGraphicsContext( _window );

if( _window->valid( ))
if( _window.valid( ))
_window->close( );
}

Expand Down
2 changes: 2 additions & 0 deletions window.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class Window : public eq::Window
virtual void swapBuffers( );

private:
struct ClearChannels;

void cleanup( );

protected:
Expand Down

0 comments on commit bed209c

Please sign in to comment.