49#include "common/glew_wrappers.hh"
50#include "OpenFlipper/BasePlugin/PluginFunctionsCore.hh"
53#if QT_VERSION_MAJOR < 6
61#include <QCommandLineParser>
72 #include <PythonInterpreter/PythonInterpreter.hh>
79 #include <Windows/windows-startup.hh>
82#include <CommandLine/CommandLineParser.hh>
92#if defined(__GLIBCXX__) || defined(__GLIBCPP__)
95std::string demangle(
const std::string& _symbol)
98 char* demangled = abi::__cxa_demangle(_symbol.c_str(),
nullptr,
nullptr, &status);
100 std::string result{demangled};
115std::string demangle(
const std::string& _symbol)
126 int size = backtrace(addresses, 20);
127 strings = backtrace_symbols(addresses, size);
128 std::cerr <<
"Stack frames: " << size << std::endl;
131 std::regex line_format{R
"(^\s*(.+)\((([^()]+)?\+(0x[0-9a-f]+))?\)\s+\[(0x[0-9a-f]+)\]\s*$)"};
132 for(
int i = 0; i < size; i++) {
133 std::string line{strings[i]};
135 std::regex_match(line, match, line_format);
136 if (!match.empty()) {
137 auto file_name = match[1].str();
138 auto symbol = demangle(match[3].str());
139 auto offset = match[4].str();
140 auto address = match[5].str();
141 std::cerr << i <<
":";
142 if (!file_name.empty()) std::cerr <<
" " << file_name <<
" ::";
143 if (!symbol.empty()) std::cerr <<
" " << symbol;
144 if (!offset.empty()) std::cerr <<
" (+" << offset <<
")";
145 if (!address.empty()) std::cerr <<
" [" << address <<
"]";
146 std::cerr << std::endl;
159void segfaultHandling (
int) {
162 std::signal(SIGSEGV, SIG_DFL);
165 std::cerr <<
"\n" << std::endl;
166 std::cerr <<
"\n" << std::endl;
167 std::cerr <<
"\33[31m" <<
"=====================================================" << std::endl;
168 std::cerr <<
"\33[31m" <<
"OpenFlipper or one of its plugins caused a Segfault." << std::endl;
169 std::cerr <<
"\33[31m" <<
"This should not happen,... Sorry :-(" << std::endl;
170 std::cerr <<
"\33[31m" <<
"=====================================================" << std::endl;
171 std::cerr <<
"\n" << std::endl;
175 std::cerr <<
"\33[0m" <<
"Trying a backtrace to show what happened last: " << std::endl;
178 std::cerr <<
"\n" << std::endl;
179 std::cerr <<
"Backtrace completed, trying to abort now ..." << std::endl;
189 std::cerr <<
"Trying to get additional information (This might fail if the memory is corrupted)." << std::endl;
191 if (OpenFlipper::Options::gui()) {
192 for (
unsigned int i = 0 ; i < 4 ; ++i) {
202#include "OpenGL/OpenGLDetection.hh"
204int main(
int argc,
char **argv)
216 for (
int i = 0; i < argc; i++) {
217 if(strlen(argv[i]) > 4) {
218 if( ( (argv[i])[0] ==
'-' ) &&
219 ( (argv[i])[1] ==
'p' ) &&
220 ( (argv[i])[2] ==
's' ) &&
221 ( (argv[i])[3] ==
'n' ) ) {
223 argv[i] = (
char *)
"";
228 OpenFlipper::Options::argc(&argc);
229 OpenFlipper::Options::argv(&argv);
232 QCoreApplication::setOrganizationName(
"VCI");
233 QCoreApplication::setApplicationName(
TOSTRING(PRODUCT_STRING));
234 QCoreApplication::setApplicationVersion(OpenFlipper::Options::coreVersion());
237 QCoreApplication* coreApp =
new QCoreApplication(argc, argv);
239 OpenFlipper::Options::initializeSettings();
241 QCommandLineParser parser;
242 QString errorMessage;
245 switch (parseCommandLine(parser, &errorMessage)) {
248 case CommandLineError:
249 fputs(qPrintable(errorMessage), stderr);
250 fputs(
"\n\n", stderr);
251 fputs(qPrintable(parser.helpText()), stderr);
253 case CommandLineVersionRequested:
254 printf(
"%s %s\n", qPrintable(QCoreApplication::applicationName()),
255 qPrintable(QCoreApplication::applicationVersion()));
257 case CommandLineHelpRequested:
273#ifndef NO_CATCH_SIGSEGV
275 std::signal(SIGSEGV, segfaultHandling);
278 OpenFlipper::Options::windowTitle(
TOSTRING(PRODUCT_STRING)
" v" + OpenFlipper::Options::coreVersion());
280 if ( !OpenFlipper::Options::nogui() ) {
283 QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
289 QSurfaceFormat resultFormat = getContextFormat();
292 OpenFlipper::Options::samples(resultFormat.samples(),
true);
293 OpenFlipper::Options::glStereo(resultFormat.stereo(),
true);
294 OpenFlipper::Options::glVersion(resultFormat.version(),
true);
295 OpenFlipper::Options::coreProfile(resultFormat.profile() == QSurfaceFormat::CoreProfile,
true);
298 QSurfaceFormat::setDefaultFormat(resultFormat);
299 QApplication app(argc, argv);
300 QOffscreenSurface *surface =
new QOffscreenSurface();
304 QOpenGLContext::globalShareContext()->makeCurrent(surface);
309#if QT_VERSION_MAJOR < 6
310 if ( !QGLFormat::hasOpenGL() ) {
312 if ( QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGL ) {
314 std::cerr <<
"This system has no OpenGL support.\n";
324 QString tLang = OpenFlipperSettings().
value(
"Core/Language/Translation",
"en_US").toString();
326 if (tLang ==
"locale")
327 tLang = QLocale::system().name();
330 QTranslator qtTranslator;
331 #if QT_VERSION_MAJOR < 6
332 qtTranslator.load(
"qt_" + tLang, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
334 if ( ! qtTranslator.load(
"qt_" + tLang, QLibraryInfo::path(QLibraryInfo::TranslationsPath)) ) {
335 std::cerr <<
"Failed to load translation files!" << std::endl;
339 app.installTranslator(&qtTranslator);
342 QString translationDir = OpenFlipper::Options::translationsDirStr() + QDir::separator();
343 QDir dir(translationDir);
344 dir.setFilter(QDir::Files);
346 QFileInfoList list = dir.entryInfoList();
348 for (
int i = 0; i < list.size(); ++i) {
349 QFileInfo fileInfo = list.at(i);
351 if ( fileInfo.baseName().contains(tLang) ){
352 QTranslator* myAppTranslator =
new QTranslator();
354 if ( myAppTranslator->load( fileInfo.filePath() ) )
356 app.installTranslator(myAppTranslator);
359 delete myAppTranslator;
371 const QStringList positionalArguments = parser.positionalArguments();
373 for (
auto file: positionalArguments ) {
381 QCoreApplication app(argc,argv);
394 const QStringList positionalArguments = parser.positionalArguments();
396 for (
auto file: positionalArguments ) {
#define TOSTRING(x)
QSettings object containing all program settings of OpenFlipper.
std::string description() const
void commandLineOpen(const QString &_filename, bool _asPolyMesh)
Load an object from the commandline on application start.
void init()
Second initialization stage.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
ACG::SceneGraph::DrawModes::DrawMode drawMode(int _viewer)
Get the current draw Mode of a Viewer.