Page 1 of 1

Suggestion: System cleanup in constructor

Posted: Fri Apr 08, 2011 16:31
by kintaroe
Hello,

I noticed that the System class constructor may throw an exception, namely here:

Code: Select all

    // handle initialisation and setup of the XML parser
    setupXMLParser();

    // now XML is available, read the configuration file (if any)
    Config_xmlHandler config;
    if (!configFile.empty())
    {
        CEGUI_TRY
        {
            d_xmlParser->parseXMLFile(config, configFile,
                                      config.CEGUIConfigSchemaName,
                                      "");
        }
        CEGUI_CATCH(...)
        {
            // cleanup XML stuff
            d_xmlParser->cleanup();
            delete d_xmlParser;
            CEGUI_RETHROW;
        }
    }


I tried to catch this exception and bootstrap system with no xml file, but it fails with assertion and exceptions, probably because other singletons have been created and have not been destroyed before rethrowing the exception.

I would like to have your opinion about this.

Thanks in advance,
kintaroe

Re: Suggestion: System cleanup in constructor

Posted: Tue Apr 19, 2011 08:14
by CrazyEddie
...it fails with assertion and exceptions ... I would like to have your opinion about this.

Why don't you mention what the assertion and exception messages are? You really don't want my opinion - I get accused of being rude and impolite enough as it is ;)

It's possible to create the system without an xml config file. Did you mean without an XML parser? If so you would have to create a 'dummy' object and pass it in to the System::create call.

This has nothing to do with not cleaning up singletons; they do not exist at that point in the code.

CE.