Hi George, On a first read your LogFileHandler looks OK, the Mutex should in theory resolve multi-threading issues. From the details you've provide one can't pinpoint what the problem might be so you'll need to work through iteratively to see what the problem areas might me. One test I'd do is comment out the _log << message; to see if it's the file handling that is suspect.
Also general things to check would be the VS issue with mixing release and debug builds at one time. Finally if are able to build and test your application on another platform. Robert. On 28 November 2011 12:03, George Bekos <[email protected]> wrote: > Hello everyone! :] > > I am trying to redirect all OSG notifications to a file by creating my own > notify handler class (inheriting from osg::NotifyHandler) but I get some > random crushes. Mostly during run-time and sometimes when I close the > application. All of them reporting some kind of heap corruption. Sometimes it > might take about 5-10 minutes in order to crush. Here is my code: > > Code: > > class LogFileHandler : public osg::NotifyHandler > { > public: > LogFileHandler(const std::string& filename) { > _log.open( filename.c_str() ); > _validFile = _log.is_open(); > } > void notify( osg::NotifySeverity severity, const char* message ) { > OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); > if(!_validFile) return; > _log << message; > } > protected: > ~LogFileHandler(void) { > _log.close(); > } > protected: > std::ofstream _log; > OpenThreads::Mutex _mutex; > bool _validFile; > }; > > > > In order to test this class I set the handler like this: > osg::setNotifyHandler( new LogFileHandler("log.txt") ); > > Why do I get crushes reporting an invalid heap? Am I doing something wrong? > OSG notes: > "Note that osg notification API is not thread safe although notification > handler is called from many threads. When incorporating handlers into GUI > widgets you must take care of thread safety on your own." > Isn't the ScopedLock I have at the top of my notify() function enough? > > If I set the osgViewer threading mode to SingleThreaded, the problem goes > away. This makes me believe that my problem has something to do with > multithreading. > I am using OSG 3.0.0 and Visual Studio 2008 SP1. > > Thanks a lot for your time. > > Cheers, > George > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=44063#44063 > > > > > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

