mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
Fix launcher crash at close
This commit is contained in:
@ -23,7 +23,7 @@ SocketLobby::SocketLobby(QObject *parent) :
|
|||||||
|
|
||||||
void SocketLobby::connectServer(const QString & host, int port, const QString & usr)
|
void SocketLobby::connectServer(const QString & host, int port, const QString & usr)
|
||||||
{
|
{
|
||||||
const int connectionTimeout = 1000;
|
const int connectionTimeout = 2000;
|
||||||
username = usr;
|
username = usr;
|
||||||
|
|
||||||
emit text("Connecting to " + host + ":" + QString::number(port));
|
emit text("Connecting to " + host + ":" + QString::number(port));
|
||||||
|
@ -113,7 +113,7 @@ void Lobby::serverCommand(const ServerCommand & command) try
|
|||||||
gameArgs << "--lobby-address" << ui->hostEdit->text();
|
gameArgs << "--lobby-address" << ui->hostEdit->text();
|
||||||
gameArgs << "--lobby-port" << ui->portEdit->text();
|
gameArgs << "--lobby-port" << ui->portEdit->text();
|
||||||
gameArgs << "--uuid" << args[0];
|
gameArgs << "--uuid" << args[0];
|
||||||
qobject_cast<MainWindow *>(qApp->activeWindow())->startGame(gameArgs);
|
startGame(gameArgs);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#include "mainwindow_moc.h"
|
#include "mainwindow_moc.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QProcess>
|
||||||
|
#include "../lib/VCMIDirs.h"
|
||||||
|
|
||||||
// Conan workaround https://github.com/conan-io/conan-center-index/issues/13332
|
// Conan workaround https://github.com/conan-io/conan-center-index/issues/13332
|
||||||
#ifdef VCMI_IOS
|
#ifdef VCMI_IOS
|
||||||
@ -19,6 +21,9 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int __argc;
|
||||||
|
char ** __argv;
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
@ -38,3 +43,45 @@ int main(int argc, char * argv[])
|
|||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void startGame(const QStringList & args)
|
||||||
|
{
|
||||||
|
__argc = args.size() + 1; //first argument is omitted
|
||||||
|
__argv = new char*[__argc];
|
||||||
|
__argv[0] = new char[strlen("vcmi")];
|
||||||
|
strcpy(__argv[0], "vcmi");
|
||||||
|
for(int i = 1; i < __argc; ++i)
|
||||||
|
{
|
||||||
|
const char * s = args[i - 1].toLocal8Bit().constData();
|
||||||
|
__argv[i] = new char[strlen(s)];
|
||||||
|
strcpy(__argv[i], s);
|
||||||
|
}
|
||||||
|
#ifdef Q_OS_IOS
|
||||||
|
logGlobal->warn("Starting game with the arguments: %s", args.join(" ").toStdString());
|
||||||
|
qApp->quit();
|
||||||
|
#else
|
||||||
|
startExecutable(pathToQString(VCMIDirs::get().clientPath()), args);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef Q_OS_IOS
|
||||||
|
void startExecutable(QString name, const QStringList & args)
|
||||||
|
{
|
||||||
|
QProcess process;
|
||||||
|
|
||||||
|
// Start the executable
|
||||||
|
if(process.startDetached(name, args))
|
||||||
|
{
|
||||||
|
qApp->quit();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox::critical(qApp->activeWindow(),
|
||||||
|
"Error starting executable",
|
||||||
|
"Failed to start " + name + "\n"
|
||||||
|
"Reason: " + process.errorString(),
|
||||||
|
QMessageBox::Ok,
|
||||||
|
QMessageBox::Ok);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -10,6 +10,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
extern int __argc;
|
extern int __argc;
|
||||||
extern char ** __argv;
|
extern char ** __argv;
|
||||||
|
|
||||||
|
void startGame(const QStringList & args);
|
||||||
|
|
||||||
#ifdef VCMI_IOS
|
#ifdef VCMI_IOS
|
||||||
extern "C" void launchGame(int argc, char * argv[]);
|
extern "C" void launchGame(int argc, char * argv[]);
|
||||||
|
#else
|
||||||
|
void startExecutable(QString name, const QStringList & args);
|
||||||
#endif
|
#endif
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#include "mainwindow_moc.h"
|
#include "mainwindow_moc.h"
|
||||||
#include "ui_mainwindow_moc.h"
|
#include "ui_mainwindow_moc.h"
|
||||||
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
#include "../lib/CConfigHandler.h"
|
#include "../lib/CConfigHandler.h"
|
||||||
@ -22,9 +21,6 @@
|
|||||||
#include "updatedialog_moc.h"
|
#include "updatedialog_moc.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
int __argc;
|
|
||||||
char ** __argv;
|
|
||||||
|
|
||||||
void MainWindow::load()
|
void MainWindow::load()
|
||||||
{
|
{
|
||||||
// Set current working dir to executable folder.
|
// Set current working dir to executable folder.
|
||||||
@ -116,48 +112,7 @@ MainWindow::~MainWindow()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::startGame(const QStringList & args)
|
|
||||||
{
|
|
||||||
__argc = args.size() + 1; //first argument is omitted
|
|
||||||
__argv = new char*[__argc];
|
|
||||||
__argv[0] = "vcmiclient";
|
|
||||||
for(int i = 1; i < __argc; ++i)
|
|
||||||
{
|
|
||||||
const char * s = args[i - 1].toLocal8Bit().constData();
|
|
||||||
__argv[i] = new char[strlen(s)];
|
|
||||||
strcpy(__argv[i], s);
|
|
||||||
}
|
|
||||||
#ifdef Q_OS_IOS
|
|
||||||
logGlobal->warn("Starting game with the arguments: %s", args.join(" ").toStdString());
|
|
||||||
qApp->quit();
|
|
||||||
#else
|
|
||||||
startExecutable(pathToQString(VCMIDirs::get().clientPath()), args);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_startGameButton_clicked()
|
void MainWindow::on_startGameButton_clicked()
|
||||||
{
|
{
|
||||||
startGame({});
|
startGame({});
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef Q_OS_IOS
|
|
||||||
void MainWindow::startExecutable(QString name, const QStringList & args)
|
|
||||||
{
|
|
||||||
QProcess process;
|
|
||||||
|
|
||||||
// Start the executable
|
|
||||||
if(process.startDetached(name, args))
|
|
||||||
{
|
|
||||||
close(); // exit launcher
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QMessageBox::critical(this,
|
|
||||||
"Error starting executable",
|
|
||||||
"Failed to start " + name + "\n"
|
|
||||||
"Reason: " + process.errorString(),
|
|
||||||
QMessageBox::Ok,
|
|
||||||
QMessageBox::Ok);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
@ -36,8 +36,6 @@ public:
|
|||||||
explicit MainWindow(QWidget * parent = 0);
|
explicit MainWindow(QWidget * parent = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
void startGame(const QStringList & args);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void on_startGameButton_clicked();
|
void on_startGameButton_clicked();
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user