Show
Ignore:
Timestamp:
05/25/09 12:46:37 (6 years ago)
Author:
robert
Message:

From Colin McDonald?, "The latest osg::notify is crashing at initialisation on Solaris, due to
constructor issues:

Within the NullStream? & NotifyStream? classes the base class objects
(ostream) were being initialised before the class member _buffer objects
which they referenced, causing a crash.

I had to move the file scope g_NullStream & g_NotifyStream initialisation
into a function to get them to work.

Also there was a missing osg:: qualifier on getNotifyHandler."

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osg/Notify.cpp

    r10229 r10263  
    3636public: 
    3737    NullStream(): 
    38         std::ostream(&_buffer) {} 
     38        std::ostream(new NullStreamBuffer) 
     39    { _buffer = dynamic_cast<NullStreamBuffer *>(rdbuf()); } 
     40         
     41    ~NullStream() 
     42    { 
     43        rdbuf(0); 
     44        delete _buffer; 
     45    } 
    3946 
    4047protected: 
    41     NullStreamBuffer _buffer; 
     48    NullStreamBuffer* _buffer; 
    4249}; 
    4350 
     
    7784public: 
    7885    NotifyStream(): 
    79         std::ostream(&_buffer) {} 
     86        std::ostream(new NotifyStreamBuffer) 
     87    { _buffer = dynamic_cast<NotifyStreamBuffer *>(rdbuf()); } 
    8088 
    8189    void setCurrentSeverity(osg::NotifySeverity severity) 
    8290    { 
    83         _buffer.setCurrentSeverity(severity); 
     91        _buffer->setCurrentSeverity(severity); 
    8492    } 
    8593 
    8694    osg::NotifySeverity getCurrentSeverity() const 
    8795    { 
    88         return _buffer.getCurrentSeverity(); 
     96        return _buffer->getCurrentSeverity(); 
     97    } 
     98         
     99    ~NotifyStream() 
     100    { 
     101        rdbuf(0); 
     102        delete _buffer; 
    89103    } 
    90104 
    91105protected: 
    92     NotifyStreamBuffer _buffer; 
     106    NotifyStreamBuffer* _buffer; 
    93107}; 
    94108 
     
    99113static osg::ApplicationUsageProxy Notify_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE, "OSG_NOTIFY_LEVEL <mode>", "FATAL | WARN | NOTICE | DEBUG_INFO | DEBUG_FP | DEBUG | INFO | ALWAYS"); 
    100114 
    101 osg::NotifySeverity g_NotifyLevel = osg::NOTICE; 
    102 osg::NullStream g_NullStream; 
    103 osg::NotifyStream g_NotifyStream; 
     115static osg::NotifySeverity g_NotifyLevel = osg::NOTICE; 
     116static osg::NullStream *g_NullStream; 
     117static osg::NotifyStream *g_NotifyStream; 
    104118 
    105119void osg::setNotifyLevel(osg::NotifySeverity severity) 
     
    118132void osg::setNotifyHandler(osg::NotifyHandler *handler) 
    119133{ 
    120     osg::NotifyStreamBuffer *buffer = static_cast<osg::NotifyStreamBuffer *>(g_NotifyStream.rdbuf()); 
     134    osg::NotifyStreamBuffer *buffer = static_cast<osg::NotifyStreamBuffer *>(g_NotifyStream->rdbuf()); 
    121135    if (buffer) 
    122136        buffer->setNotifyHandler(handler); 
    123137} 
    124138 
    125 osg::NotifyHandler *getNotifyHandler() 
     139osg::NotifyHandler* osg::getNotifyHandler() 
    126140{ 
    127141    osg::initNotifyLevel(); 
    128     osg::NotifyStreamBuffer *buffer = static_cast<osg::NotifyStreamBuffer *>(g_NotifyStream.rdbuf()); 
     142    osg::NotifyStreamBuffer *buffer = static_cast<osg::NotifyStreamBuffer *>(g_NotifyStream->rdbuf()); 
    129143    return buffer ? buffer->getNotifyHandler() : 0; 
    130144} 
     
    133147{ 
    134148    static bool s_NotifyInit = false; 
     149    static osg::NullStream s_NullStream; 
     150    static osg::NotifyStream s_NotifyStream; 
    135151 
    136152    if (s_NotifyInit) return true; 
     153 
     154    g_NullStream = &s_NullStream; 
     155    g_NotifyStream = &s_NotifyStream; 
    137156     
    138157    // g_NotifyLevel 
     
    169188 
    170189    // Setup standard notify handler 
    171     osg::NotifyStreamBuffer *buffer = dynamic_cast<osg::NotifyStreamBuffer *>(g_NotifyStream.rdbuf()); 
     190    osg::NotifyStreamBuffer *buffer = dynamic_cast<osg::NotifyStreamBuffer *>(g_NotifyStream->rdbuf()); 
    172191    if (buffer && !buffer->getNotifyHandler()) 
    173192        buffer->setNotifyHandler(new StandardNotifyHandler); 
     
    194213    if (severity<=g_NotifyLevel) 
    195214    { 
    196         g_NotifyStream.setCurrentSeverity(severity); 
    197         return g_NotifyStream; 
    198     } 
    199     return g_NullStream; 
     215        g_NotifyStream->setCurrentSeverity(severity); 
     216        return *g_NotifyStream; 
     217    } 
     218    return *g_NullStream; 
    200219} 
    201220