From 6d6ade623e872e6a25238129504b14a0e6292f9f Mon Sep 17 00:00:00 2001 From: "Zane U. Ji" Date: Sat, 11 Aug 2012 07:50:42 +0800 Subject: [PATCH] Don't initialize/terminate Xerces-C++ over and over again. It leads to crash when several files are opened on startup. This could be the root cause of some startup crashes, e.g. bug #2787738 and bug #2825812. --- src/wrapxerces.cpp | 9 --------- src/xmlcopyeditor.cpp | 15 +++++++++++++++ src/xmlpromptgenerator.cpp | 16 +--------------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/wrapxerces.cpp b/src/wrapxerces.cpp index 74f05a2..4696df0 100755 --- a/src/wrapxerces.cpp +++ b/src/wrapxerces.cpp @@ -33,14 +33,6 @@ using namespace xercesc; WrapXerces::WrapXerces( std::string catalogPath, std::string catalogUtilityPath ) { - try - { - XMLPlatformUtils::Initialize(); - } - catch ( XMLException& e ) - { - throw std::runtime_error ( "Cannot initialize Xerces" ); - } errorPosition = std::make_pair ( 1, 1 ); catalogResolver = new XercesCatalogResolver( catalogPath, catalogUtilityPath ); } @@ -48,7 +40,6 @@ WrapXerces::WrapXerces( std::string catalogPath, std::string catalogUtilityPath WrapXerces::~WrapXerces() { delete catalogResolver; - XMLPlatformUtils::Terminate(); } bool WrapXerces::validate ( const std::string& fileName ) diff --git a/src/xmlcopyeditor.cpp b/src/xmlcopyeditor.cpp index 5dd7c7d..e538a19 100755 --- a/src/xmlcopyeditor.cpp +++ b/src/xmlcopyeditor.cpp @@ -312,6 +312,9 @@ MyApp::~MyApp() delete checker; delete server; delete connection; + + // Terminate Xerces-C++ + XMLPlatformUtils::Terminate(); } bool MyApp::OnInit() @@ -371,6 +374,10 @@ bool MyApp::OnInit() { wxImage::AddHandler ( new wxPNGHandler ); wxSystemOptions::SetOption ( _T ( "msw.remap" ), 0 ); + + // Initialize Xerces-C++ + XMLPlatformUtils::Initialize(); + frame = new MyFrame ( _ ( "XML Copy Editor" ), config.get(), @@ -381,6 +388,14 @@ bool MyApp::OnInit() if ( frame->getHandleCommandLineFlag() ) frame->handleCommandLine(); } + catch ( const XMLException &e ) + { + wxString error; + error << _ ( "Failed to initialize Xerces-c:\n" ) + << WrapXerces::toString ( e.getMessage() ); + wxMessageBox ( error, _ ( "Error" ), wxOK | wxICON_ERROR ); + return false; + } catch ( exception &e ) { const char *what; diff --git a/src/xmlpromptgenerator.cpp b/src/xmlpromptgenerator.cpp index 32cad88..23d36c0 100755 --- a/src/xmlpromptgenerator.cpp +++ b/src/xmlpromptgenerator.cpp @@ -435,17 +435,6 @@ void XmlPromptGenerator::handleSchema ( std::string schemaPath = PathResolver::run ( path, ( d->auxPath.empty() ) ? d->basePath : d->auxPath); - - try - { - XMLPlatformUtils::Initialize(); - } - catch ( const XMLException& toCatch ) - { - XMLPlatformUtils::Terminate(); - return; - } - XercesDOMParser *parser = new XercesDOMParser(); parser->setDoNamespaces ( true ); parser->setDoSchema ( true ); @@ -455,8 +444,7 @@ void XmlPromptGenerator::handleSchema ( if ( !rootGrammar ) { delete parser; - XMLPlatformUtils::Terminate(); - return; + return; } SchemaGrammar* grammar = ( SchemaGrammar* ) rootGrammar; @@ -466,7 +454,6 @@ void XmlPromptGenerator::handleSchema ( { delete grammar; delete parser; - XMLPlatformUtils::Terminate(); return; } @@ -526,7 +513,6 @@ void XmlPromptGenerator::handleSchema ( } } delete parser; - XMLPlatformUtils::Terminate(); } void XmlPromptGenerator::getContent (