Re: [osg-users] Custom osg::NotifyHandler problems and multi-threading
Thank you very much for your reply Robert! When (and if) I find some time I will look into microsoft's stream implementation code. I have one last question though: Is the int NotifyStreamBuffer::sync(void) function in file Notify.cpp thread-safe? I am not sure how those sputc(),pubseekpos(),sync() functions work. Although I guess I figure it out when I look into microsoft's code. Thanks again Robert. Cheers, George -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=44211#44211 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Custom osg::NotifyHandler problems and multi-threading
Hello again! Thanks for your reply Robert. I want to apologise because I was wrong when I said that the problem goes away when you remove the _logmessage line. Even if I have an empty osg::NotifyHandler::notify() function, it will still crush (although it might take some time)! This is what I have now: Code: #include osg/Group #include osg/Notify #include osgViewer/Viewer class LogFileHandler : public osg::NotifyHandler { public: LogFileHandler(void) {} void notify( osg::NotifySeverity severity, const char* message ) {} protected: ~LogFileHandler(void) {} }; int main( int agc, char** argv ) { osg::setNotifyLevel(osg::DEBUG_FP); osg::Group* root = new osg::Group(); LogFileHandler* fileHandler = new LogFileHandler(); osg::setNotifyHandler(fileHandler); osgViewer::Viewer viewer; viewer.setSceneData(root); viewer.setUpViewInWindow(50,50,800,600); viewer.run(); return 0; } Here is a call stack from the crush: Code: msvcr90d.dll!operator delete(void * pUserData=0x00908740) Line 52 + 0x51 bytes C++ msvcp90d.dll!std::allocatorunsigned short::deallocate(unsigned short * _Ptr=0x00908740, unsigned int __formal=102) Line 146 + 0x9 bytes C++ msvcp90d.dll!std::basic_stringbufchar,std::char_traitschar,std::allocatorchar ::overflow(int _Meta=0) Line 148 C++ msvcp90d.dll!std::basic_streambufchar,std::char_traitschar ::sputc(char _Ch=0) Line 163 + 0x4a bytes C++ osg80-osgd.dll!osg::NotifyStreamBuffer::sync() Line 73 + 0xd bytes C++ msvcp90d.dll!std::basic_streambufunsigned short,std::char_traitsunsigned short ::pubsync() Line 101C++ msvcp90d.dll!std::basic_ostreamunsigned short,std::char_traitsunsigned short ::flush() Line 552 + 0x30 bytes C++ msvcp90d.dll!std::endl(std::basic_ostreamchar,std::char_traitschar _Ostr={...}) Line 975C++ msvcp90d.dll!std::basic_ostreamunsigned short,std::char_traitsunsigned short ::operator(std::basic_ostreamunsigned short,std::char_traitsunsigned short (std::basic_ostreamunsigned short,std::char_traitsunsigned short )* _Pfn=0x65983a20) Line 173 + 0x7 bytes C++ osg80-osgViewerd.dll!osgViewer::Renderer::draw() Line 645 + 0x63 bytes C++ Although the last 4 calls (sputc() call to operator delete call) are the same most of the time. Any ideas what is going on? Are all the classes and functions invoked after using basic_ostream::operator supposed to be thread safe? If not, does OSG access these functions in a thread-safe way? It crushes on both OSG 3.0.0 and 3.0.1 (two different machines). With visual Studio 2008 SP1 and Win7x64. Thanks a lot for your time. Cheers, George -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=44167#44167 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Custom osg::NotifyHandler problems and multi-threading
Hi George, I'm afraid I really can't help you it hunting down what the issue is as I haven't used Windows for development for over a decade. I have read that are problems with MS's stream implementation which may well be what is the root cause of the problems you are seeing. Try another platform to see if this gives you any more insight. Robert. On 1 December 2011 16:35, George Bekos bekos...@live.com wrote: Hello again! Thanks for your reply Robert. I want to apologise because I was wrong when I said that the problem goes away when you remove the _logmessage line. Even if I have an empty osg::NotifyHandler::notify() function, it will still crush (although it might take some time)! This is what I have now: Code: #include osg/Group #include osg/Notify #include osgViewer/Viewer class LogFileHandler : public osg::NotifyHandler { public: LogFileHandler(void) {} void notify( osg::NotifySeverity severity, const char* message ) {} protected: ~LogFileHandler(void) {} }; int main( int agc, char** argv ) { osg::setNotifyLevel(osg::DEBUG_FP); osg::Group* root = new osg::Group(); LogFileHandler* fileHandler = new LogFileHandler(); osg::setNotifyHandler(fileHandler); osgViewer::Viewer viewer; viewer.setSceneData(root); viewer.setUpViewInWindow(50,50,800,600); viewer.run(); return 0; } Here is a call stack from the crush: Code: msvcr90d.dll!operator delete(void * pUserData=0x00908740) Line 52 + 0x51 bytes C++ msvcp90d.dll!std::allocatorunsigned short::deallocate(unsigned short * _Ptr=0x00908740, unsigned int __formal=102) Line 146 + 0x9 bytes C++ msvcp90d.dll!std::basic_stringbufchar,std::char_traitschar,std::allocatorchar ::overflow(int _Meta=0) Line 148 C++ msvcp90d.dll!std::basic_streambufchar,std::char_traitschar ::sputc(char _Ch=0) Line 163 + 0x4a bytes C++ osg80-osgd.dll!osg::NotifyStreamBuffer::sync() Line 73 + 0xd bytes C++ msvcp90d.dll!std::basic_streambufunsigned short,std::char_traitsunsigned short ::pubsync() Line 101 C++ msvcp90d.dll!std::basic_ostreamunsigned short,std::char_traitsunsigned short ::flush() Line 552 + 0x30 bytes C++ msvcp90d.dll!std::endl(std::basic_ostreamchar,std::char_traitschar _Ostr={...}) Line 975 C++ msvcp90d.dll!std::basic_ostreamunsigned short,std::char_traitsunsigned short ::operator(std::basic_ostreamunsigned short,std::char_traitsunsigned short (std::basic_ostreamunsigned short,std::char_traitsunsigned short )* _Pfn=0x65983a20) Line 173 + 0x7 bytes C++ osg80-osgViewerd.dll!osgViewer::Renderer::draw() Line 645 + 0x63 bytes C++ Although the last 4 calls (sputc() call to operator delete call) are the same most of the time. Any ideas what is going on? Are all the classes and functions invoked after using basic_ostream::operator supposed to be thread safe? If not, does OSG access these functions in a thread-safe way? It crushes on both OSG 3.0.0 and 3.0.1 (two different machines). With visual Studio 2008 SP1 and Win7x64. Thanks a lot for your time. Cheers, George -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=44167#44167 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Custom osg::NotifyHandler problems and multi-threading
Hi George, The effect of removing the _logmessage suggests to me that the MS implementation does something odd making it unreliable when being called from multiple threads. Try replacing the _logmessage with a fprintf or equivalent C function to see if that helps. Robert. On 29 November 2011 11:38, George Bekos bekos...@live.com wrote: Hello Robert, Thank you very much for your reply. I did remove the _log message; line and the problem goes away. When I get the crush, in which VStudio reports heap corruption, I use the debugger to have a look at the corrupted memory block, and it always points to some region where the notice strings are saved. In my program I do not do anything fancy. It is an extremely simple case: Code: #include cstdlib #include osg/Group #include osgViewer/Viewer #include LogFileHandler.h // - class MyUpdateCallback : public osg::NodeCallback { virtual void operator()( osg::Node* node, osg::NodeVisitor* nv) { for(size_t i = 0; i 1000; ++i) { osg::notify( osg::NOTICE ) hello!;// std::endl; } } }; // - int main( int agc, char** argv ) { osg::setNotifyLevel(osg::DEBUG_FP); osg::Group* root = new osg::Group(); LogFileHandler* fileHandler = new LogFileHandler(log.txt); osg::setNotifyHandler(fileHandler); root-setUpdateCallback(new MyUpdateCallback()); osgViewer::Viewer viewer; viewer.setSceneData(root); viewer.setUpViewInWindow(50,50,800,600); viewer.run(); return EXIT_SUCCESS; } When I check the corrupted memory block sometimes I see something like hello!!hello!!hel«þîþîþ..þîþþîþþîþþîþ. Which looks corrupted to me. If I add an std::endl at the end of my message in the above callback the problem still appears but not very often. I have tried this program on 2 different PCs but both of them had windows7x64. I checked my lib and dll files, I do not mix release and debug builds. The problem is very strange... I guess I am missing something. Thanks for your help! Cheers, George -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=44106#44106 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Custom osg::NotifyHandler problems and multi-threading
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 bekos...@live.com 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::ScopedLockOpenThreads::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 osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Custom osg::NotifyHandler problems and multi-threading
Hello Robert, Thank you very much for your reply. I did remove the _log message; line and the problem goes away. When I get the crush, in which VStudio reports heap corruption, I use the debugger to have a look at the corrupted memory block, and it always points to some region where the notice strings are saved. In my program I do not do anything fancy. It is an extremely simple case: Code: #include cstdlib #include osg/Group #include osgViewer/Viewer #include LogFileHandler.h // - class MyUpdateCallback : public osg::NodeCallback { virtual void operator()( osg::Node* node, osg::NodeVisitor* nv) { for(size_t i = 0; i 1000; ++i) { osg::notify( osg::NOTICE ) hello!;// std::endl; } } }; // - int main( int agc, char** argv ) { osg::setNotifyLevel(osg::DEBUG_FP); osg::Group* root = new osg::Group(); LogFileHandler* fileHandler = new LogFileHandler(log.txt); osg::setNotifyHandler(fileHandler); root-setUpdateCallback(new MyUpdateCallback()); osgViewer::Viewer viewer; viewer.setSceneData(root); viewer.setUpViewInWindow(50,50,800,600); viewer.run(); return EXIT_SUCCESS; } When I check the corrupted memory block sometimes I see something like hello!!hello!!hel«þîþîþ..þîþþîþþîþþîþ. Which looks corrupted to me. If I add an std::endl at the end of my message in the above callback the problem still appears but not very often. I have tried this program on 2 different PCs but both of them had windows7x64. I checked my lib and dll files, I do not mix release and debug builds. The problem is very strange... I guess I am missing something. Thanks for your help! Cheers, George -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=44106#44106 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Custom osg::NotifyHandler problems and multi-threading
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::ScopedLockOpenThreads::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 osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org