Don't use std::exit during Qt initialization

This commit is contained in:
Megamouse 2021-02-05 15:36:57 +01:00
parent 7ce835e878
commit 2865865382
12 changed files with 62 additions and 22 deletions

View File

@ -13,7 +13,7 @@ headless_application::headless_application(int& argc, char** argv) : QCoreApplic
{ {
} }
void headless_application::Init() bool headless_application::Init()
{ {
// Force init the emulator // Force init the emulator
InitializeEmulator("00000001", true, false); // TODO: get user from cli args if possible InitializeEmulator("00000001", true, false); // TODO: get user from cli args if possible
@ -26,6 +26,8 @@ void headless_application::Init()
// As per QT recommendations to avoid conflicts for POSIX functions // As per QT recommendations to avoid conflicts for POSIX functions
std::setlocale(LC_NUMERIC, "C"); std::setlocale(LC_NUMERIC, "C");
return true;
} }
void headless_application::InitializeConnects() void headless_application::InitializeConnects()

View File

@ -17,7 +17,7 @@ public:
headless_application(int& argc, char** argv); headless_application(int& argc, char** argv);
/** Call this method before calling app.exec */ /** Call this method before calling app.exec */
void Init() override; bool Init() override;
private: private:
void InitializeCallbacks(); void InitializeCallbacks();

View File

@ -507,17 +507,28 @@ int main(int argc, char** argv)
gui_app->SetShowGui(!s_no_gui); gui_app->SetShowGui(!s_no_gui);
gui_app->SetUseCliStyle(use_cli_style); gui_app->SetUseCliStyle(use_cli_style);
gui_app->Init();
if (!gui_app->Init())
{
Emu.Quit(true);
return 0;
}
} }
else if (auto headless_app = qobject_cast<headless_application*>(app.data())) else if (auto headless_app = qobject_cast<headless_application*>(app.data()))
{ {
s_headless = true; s_headless = true;
headless_app->Init();
if (!headless_app->Init())
{
Emu.Quit(true);
return 0;
}
} }
else else
{ {
// Should be unreachable // Should be unreachable
report_fatal_error("RPCS3 initialization failed!"); report_fatal_error("RPCS3 initialization failed!");
return 1;
} }
#ifdef _WIN32 #ifdef _WIN32

View File

@ -8,7 +8,7 @@ struct EmuCallbacks;
class main_application class main_application
{ {
public: public:
virtual void Init() = 0; virtual bool Init() = 0;
static bool InitializeEmulator(const std::string& user, bool force_init, bool show_gui); static bool InitializeEmulator(const std::string& user, bool force_init, bool show_gui);

View File

@ -63,13 +63,27 @@ namespace
emu_settings::emu_settings() emu_settings::emu_settings()
: QObject() : QObject()
, m_render_creator(new render_creator(this))
{ {
}
emu_settings::~emu_settings()
{
}
bool emu_settings::Init()
{
m_render_creator = new render_creator(this);
if (!m_render_creator) if (!m_render_creator)
{ {
fmt::throw_exception("emu_settings::emu_settings() render_creator is null"); fmt::throw_exception("emu_settings::emu_settings() render_creator is null");
} }
if (m_render_creator->abort_requested)
{
return false;
}
// Make Vulkan default setting if it is supported // Make Vulkan default setting if it is supported
if (m_render_creator->Vulkan.supported && !m_render_creator->Vulkan.adapters.empty()) if (m_render_creator->Vulkan.supported && !m_render_creator->Vulkan.adapters.empty())
{ {
@ -78,10 +92,8 @@ emu_settings::emu_settings()
Emu.SetDefaultRenderer(video_renderer::vulkan); Emu.SetDefaultRenderer(video_renderer::vulkan);
Emu.SetDefaultGraphicsAdapter(adapter); Emu.SetDefaultGraphicsAdapter(adapter);
} }
}
emu_settings::~emu_settings() return true;
{
} }
void emu_settings::LoadSettings(const std::string& title_id) void emu_settings::LoadSettings(const std::string& title_id)

View File

@ -35,6 +35,8 @@ public:
emu_settings(); emu_settings();
~emu_settings(); ~emu_settings();
bool Init();
/** Connects a combo box with the target settings type*/ /** Connects a combo box with the target settings type*/
void EnhanceComboBox(QComboBox* combobox, emu_settings_type type, bool is_ranged = false, bool use_max = false, int max = 0, bool sorted = false); void EnhanceComboBox(QComboBox* combobox, emu_settings_type type, bool is_ranged = false, bool use_max = false, int max = 0, bool sorted = false);
@ -75,7 +77,7 @@ public:
void SetSetting(emu_settings_type type, const std::string& val); void SetSetting(emu_settings_type type, const std::string& val);
/** Gets all the renderer info for gpu settings.*/ /** Gets all the renderer info for gpu settings.*/
render_creator* m_render_creator; render_creator* m_render_creator = nullptr;
/** Gets a list of all the microphones available.*/ /** Gets a list of all the microphones available.*/
microphone_creator m_microphone_creator; microphone_creator m_microphone_creator;

View File

@ -50,7 +50,7 @@ gui_application::~gui_application()
#endif #endif
} }
void gui_application::Init() bool gui_application::Init()
{ {
setWindowIcon(QIcon(":/rpcs3.ico")); setWindowIcon(QIcon(":/rpcs3.ico"));
@ -58,6 +58,11 @@ void gui_application::Init()
m_gui_settings.reset(new gui_settings()); m_gui_settings.reset(new gui_settings());
m_persistent_settings.reset(new persistent_settings()); m_persistent_settings.reset(new persistent_settings());
if (!m_emu_settings->Init())
{
return false;
}
// Get deprecated active user (before August 2nd 2020) // Get deprecated active user (before August 2nd 2020)
QString active_user = m_gui_settings->GetValue(gui::um_active_user).toString(); QString active_user = m_gui_settings->GetValue(gui::um_active_user).toString();
@ -91,9 +96,9 @@ void gui_application::Init()
welcome->exec(); welcome->exec();
} }
if (m_main_window) if (m_main_window && !m_main_window->Init())
{ {
m_main_window->Init(); return false;
} }
#ifdef WITH_DISCORD_RPC #ifdef WITH_DISCORD_RPC
@ -103,6 +108,8 @@ void gui_application::Init()
discord::initialize(); discord::initialize();
} }
#endif #endif
return true;
} }
void gui_application::SwitchTranslator(QTranslator& translator, const QString& filename, const QString& language_code) void gui_application::SwitchTranslator(QTranslator& translator, const QString& filename, const QString& language_code)

View File

@ -39,7 +39,7 @@ public:
} }
/** Call this method before calling app.exec */ /** Call this method before calling app.exec */
void Init() override; bool Init() override;
std::unique_ptr<gs_frame> get_gs_frame(); std::unique_ptr<gs_frame> get_gs_frame();

View File

@ -82,7 +82,7 @@ main_window::~main_window()
/* An init method is used so that RPCS3App can create the necessary connects before calling init (specifically the stylesheet connect). /* An init method is used so that RPCS3App can create the necessary connects before calling init (specifically the stylesheet connect).
* Simplifies logic a bit. * Simplifies logic a bit.
*/ */
void main_window::Init() bool main_window::Init()
{ {
setAcceptDrops(true); setAcceptDrops(true);
@ -127,7 +127,7 @@ void main_window::Init()
if (msg.exec() == QMessageBox::No) if (msg.exec() == QMessageBox::No)
{ {
std::exit(EXIT_SUCCESS); return false;
} }
} }
@ -227,6 +227,8 @@ void main_window::Init()
m_updater.check_for_updates(true, update_value != "true", this); m_updater.check_for_updates(true, update_value != "true", this);
} }
#endif #endif
return true;
} }
QString main_window::GetCurrentTitle() QString main_window::GetCurrentTitle()

View File

@ -81,7 +81,7 @@ class main_window : public QMainWindow
public: public:
explicit main_window(std::shared_ptr<gui_settings> gui_settings, std::shared_ptr<emu_settings> emu_settings, std::shared_ptr<persistent_settings> persistent_settings, QWidget *parent = 0); explicit main_window(std::shared_ptr<gui_settings> gui_settings, std::shared_ptr<emu_settings> emu_settings, std::shared_ptr<persistent_settings> persistent_settings, QWidget *parent = 0);
void Init(); bool Init();
~main_window(); ~main_window();
QIcon GetAppIcon(); QIcon GetAppIcon();

View File

@ -77,7 +77,10 @@ render_creator::render_creator(QObject *parent) : QObject(parent)
enum_thread.detach(); enum_thread.detach();
if (button != QMessageBox::Ignore) if (button != QMessageBox::Ignore)
std::exit(1); {
abort_requested = true;
return;
}
supports_vulkan = false; supports_vulkan = false;
} }

View File

@ -11,6 +11,10 @@ class render_creator : public QObject
Q_OBJECT Q_OBJECT
public: public:
render_creator(QObject* parent);
void update_names(const QStringList& names);
struct render_info struct render_info
{ {
QString name; QString name;
@ -31,14 +35,11 @@ public:
, has_msaa(has_msaa) {} , has_msaa(has_msaa) {}
}; };
bool abort_requested = false;
bool supports_vulkan = false; bool supports_vulkan = false;
QStringList vulkan_adapters; QStringList vulkan_adapters;
render_info Vulkan; render_info Vulkan;
render_info OpenGL; render_info OpenGL;
render_info NullRender; render_info NullRender;
std::vector<render_info*> renderers; std::vector<render_info*> renderers;
render_creator(QObject *parent);
void update_names(const QStringList& names);
}; };