openFrameworks icon indicating copy to clipboard operation
openFrameworks copied to clipboard

Crash when saving ofXml on exit() callback

Open armadillu opened this issue 7 years ago • 8 comments

On VisualStudio 2015 WIN 10 here;

A simple ofApp that tries to save an ofXml on exit() crashes somewhere in boost;

Unhandled exception thrown: read access violation.
this->_Ptr->_Facetvec was 0x111011101110111.
    BaseApp_debug.exe!std::locale::_Getfacet(unsigned __int64 _Id) Line 459 C++
    BaseApp_debug.exe!std::use_facet<std::codecvt<wchar_t,char,_Mbstatet> >(const std::locale & _Loc) Line 564  C++
    BaseApp_debug.exe!boost::filesystem::path::codecvt() Line 904   C++
    BaseApp_debug.exe!boost::filesystem::path_traits::convert(const char * from, const char * from_end, std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > & to) Line 837    C++
    BaseApp_debug.exe!boost::filesystem::path_traits::dispatch<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > >(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & c, std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > & to) Line 256 C++
    BaseApp_debug.exe!boost::filesystem::path::path<char [9]>(const char[9] & source, void * __formal) Line 140 C++
    BaseApp_debug.exe!ofApp::exit() Line 15 C++
    BaseApp_debug.exe!ofBaseApp::exit(ofEventArgs & args) Line 72   C++
    BaseApp_debug.exe!ofEvent<ofEventArgs,std::recursive_mutex>::make_function::__l2::<lambda>(const void * __formal, ofEventArgs & t) Line 440 C++
    [External Code] 
    BaseApp_debug.exe!of::priv::Function<ofEventArgs,std::recursive_mutex>::notify(const void * s, ofEventArgs & t) Line 90 C++
    BaseApp_debug.exe!ofEvent<ofEventArgs,std::recursive_mutex>::notify(const void * sender, ofEventArgs & param) Line 524  C++
    BaseApp_debug.exe!ofNotifyEvent<ofEvent<ofEventArgs,std::recursive_mutex>,ofEventArgs,ofMainLoop>(ofEvent<ofEventArgs,std::recursive_mutex> & event, ofEventArgs & args, ofMainLoop * sender) Line 210  C++
    BaseApp_debug.exe!ofMainLoop::exit() Line 169   C++
    BaseApp_debug.exe!ofExitCallback() Line 235 C++

The code is super simple:

class ofApp : public ofBaseApp{
    public:
    void exit() {
        ofXml s;
        s.save("test.xml");
    }
}

Saving the xml is totally fine when I attempt to do it while the app is running; so it must be something related to the exit() call;

armadillu avatar Oct 05 '16 18:10 armadillu

Going to close this as I'm not seeing it anymore in OF master branch.

armadillu avatar Jan 31 '17 00:01 armadillu

Coming across this again...

armadillu avatar Jan 04 '18 20:01 armadillu

For anyone coming across this, I patched it on my end by avoiding using any boost:filesystem::path related objects on the OF exit callback.

See here: https://github.com/armadillu/ofxRemoteUI/commit/91f11e71da939a1f07daf40458e9f315075561ea#diff-7e55cdd5e41e7c49b0342a29ff1c8ec0R537

armadillu avatar Jan 04 '18 21:01 armadillu

I came across this same exact error in a completely different codebase. I'm using Windows VS2015 x64 with stdcpp14. My boost lib version is boost/1.66.0@conan/stable.

There is a thread about this here: https://svn.boost.org/trac10/ticket/6638

adaviding avatar Jul 30 '18 22:07 adaviding

This is still an issue with my multi-window app. I use ofSetEscapeQuitsApp(false) to fix it, although it's not a real fix.

tobiasebsen avatar Oct 11 '21 07:10 tobiasebsen

I've also just come across this issue in a multi-window app.

neilmendoza avatar May 24 '22 00:05 neilmendoza

which platform are you using?

dimitre avatar May 24 '22 01:05 dimitre

I'm using Windows 10 and Visual Studio. I worked around it by calling ofToDataPath() in setup() and then using an ofstream as @armadillu mentioned above.

neilmendoza avatar May 24 '22 01:05 neilmendoza