Show
Ignore:
Timestamp:
06/08/07 11:45:11 (7 years ago)
Author:
robert
Message:

Added clean up of the view before destruction of the window

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgviewerGLUT/osgviewerGLUT.cpp

    r6864 r6899  
    2020 
    2121osg::ref_ptr<osgViewer::Viewer> viewer; 
    22 osg::ref_ptr<osgViewer::GraphicsWindow> window; 
     22osg::observer_ptr<osgViewer::GraphicsWindow> window; 
    2323 
    2424void display(void) 
    2525{ 
    2626    // update and render the scene graph 
    27     viewer->frame(); 
     27    if (viewer.valid()) viewer->frame(); 
    2828 
    2929    // Swap Buffers 
     
    3535{ 
    3636    // update the window dimensions, in case the window has been resized. 
    37     window->resized(window->getTraits()->x, window->getTraits()->y, w, h); 
    38     window->getEventQueue()->windowResize(window->getTraits()->x, window->getTraits()->y, w, h ); 
     37    if (window.valid())  
     38    { 
     39        window->resized(window->getTraits()->x, window->getTraits()->y, w, h); 
     40        window->getEventQueue()->windowResize(window->getTraits()->x, window->getTraits()->y, w, h ); 
     41    } 
    3942} 
    4043 
    4144void mousebutton( int button, int state, int x, int y ) 
    4245{ 
    43     if (state==0) window->getEventQueue()->mouseButtonPress( x, y, button+1 ); 
    44     else window->getEventQueue()->mouseButtonRelease( x, y, button+1 ); 
     46    if (window.valid()) 
     47    { 
     48        if (state==0) window->getEventQueue()->mouseButtonPress( x, y, button+1 ); 
     49        else window->getEventQueue()->mouseButtonRelease( x, y, button+1 ); 
     50    } 
    4551} 
    4652 
    4753void mousemove( int x, int y ) 
    4854{ 
    49     window->getEventQueue()->mouseMotion( x, y ); 
     55    if (window.valid()) 
     56    { 
     57        window->getEventQueue()->mouseMotion( x, y ); 
     58    } 
    5059} 
    5160 
     
    5564    { 
    5665        case 27: 
     66            // clean up the viewer  
     67            if (viewer.valid()) viewer = 0; 
    5768            glutDestroyWindow(glutGetWindow()); 
    5869            break; 
    5970        default: 
    60             window->getEventQueue()->keyPress( (osgGA::GUIEventAdapter::KeySymbol) key ); 
    61             window->getEventQueue()->keyRelease( (osgGA::GUIEventAdapter::KeySymbol) key ); 
     71            if (window.valid()) 
     72            { 
     73                window->getEventQueue()->keyPress( (osgGA::GUIEventAdapter::KeySymbol) key ); 
     74                window->getEventQueue()->keyRelease( (osgGA::GUIEventAdapter::KeySymbol) key ); 
     75            } 
    6276            break; 
    6377    }