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.

This commit is contained in:
Zane U. Ji 2012-08-11 07:50:42 +08:00
parent bfd582bdd1
commit 6d6ade623e
3 changed files with 16 additions and 24 deletions

View File

@ -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 )

View File

@ -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;

View File

@ -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,7 +444,6 @@ void XmlPromptGenerator::handleSchema (
if ( !rootGrammar )
{
delete parser;
XMLPlatformUtils::Terminate();
return;
}
@ -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 (