Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7816


Ignore:
Timestamp:
Dec 26, 2010, 5:16:12 PM (13 years ago)
Author:
rgrieder
Message:

Improved exception handling in sandbox Qt.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/forks/sandbox_qt/src/orxonox/Main.cc

    r7430 r7816  
    3636#include "Main.h"
    3737
     38#include <memory>
    3839#include <QApplication>
    3940#include <QCoreApplication>
    4041
     42#ifdef ORXONOX_PLATFORM_WINDOWS
     43#  include <windows.h>
     44#endif
     45
    4146#include "util/Debug.h"
     47#include "util/Exception.h"
    4248#include "core/CommandLineParser.h"
    4349#include "core/Core.h"
     
    5763        QApplication app(argc, argv);
    5864
    59         QStringList arguments = QCoreApplication::arguments();
    60         if (!arguments.value(0).isEmpty() && arguments.value(0)[0] != '-')
    61             arguments.pop_front(); // Remove application path
    62         Core core(arguments.join(" ").toStdString());
     65        std::auto_ptr<Core> core;
     66        try
     67        {
     68            QStringList arguments = QCoreApplication::arguments();
     69            if (!arguments.value(0).isEmpty() && arguments.value(0)[0] != '-')
     70                arguments.pop_front(); // Remove application path
     71            core.reset(new Core(arguments.join(" ").toStdString()));
     72        }
     73        catch (const Exception& ex)
     74        {
     75            COUT(0) << "Exception: " << ex.getDescription() << endl;
     76#ifdef ORXONOX_PLATFORM_WINDOWS
     77            MessageBox(NULL, ex.getDescription().c_str(), "Exception", MB_ICONERROR);
     78#endif
     79            return 1;
     80        }
    6381
    6482        QCoreApplication::setOrganizationName("Orxonox");
     
    7189        QCoreApplication::setApplicationVersion(versionString);
    7290
    73         if (CommandLineParser::getValue("generateDoc").toString().isEmpty())
     91        // Define library path
     92        // Note: May not work (untested) because QApplication was already created.
     93        // However doing the beforehand is difficult because the Core is required.
     94        QStringList libraryPaths = QCoreApplication::libraryPaths();
     95        libraryPaths.prepend(PathConfig::getExecutablePath().path() + "/plugins");
     96        QCoreApplication::setLibraryPaths(libraryPaths);
     97
     98        try
    7499        {
    75             MainWindow window;
    76             window.show();
    77             return app.exec();
     100            if (CommandLineParser::getValue("generateDoc").toString().isEmpty())
     101            {
     102                MainWindow window;
     103                window.show();
     104                return app.exec();
     105            }
     106            else
     107                return 0;
    78108        }
    79         else
    80             return 0;
     109        catch (const Exception& ex)
     110        {
     111            COUT(0) << "Exception: " << ex.getDescription() << endl;
     112#ifdef ORXONOX_PLATFORM_WINDOWS
     113            MessageBox(NULL, ex.getDescription().c_str(), "Exception", MB_ICONERROR);
     114#endif
     115            return 1;
     116        }
    81117    }
    82118}
Note: See TracChangeset for help on using the changeset viewer.