diff --git a/rpcs3/headless_application.cpp b/rpcs3/headless_application.cpp index a0eee215d6..a37f027170 100644 --- a/rpcs3/headless_application.cpp +++ b/rpcs3/headless_application.cpp @@ -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 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 std::setlocale(LC_NUMERIC, "C"); + + return true; } void headless_application::InitializeConnects() diff --git a/rpcs3/headless_application.h b/rpcs3/headless_application.h index 70b3069f23..a16ed33f7f 100644 --- a/rpcs3/headless_application.h +++ b/rpcs3/headless_application.h @@ -17,7 +17,7 @@ public: headless_application(int& argc, char** argv); /** Call this method before calling app.exec */ - void Init() override; + bool Init() override; private: void InitializeCallbacks(); diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index 5269830c33..e3ac8216ca 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -507,17 +507,28 @@ int main(int argc, char** argv) gui_app->SetShowGui(!s_no_gui); 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(app.data())) { s_headless = true; - headless_app->Init(); + + if (!headless_app->Init()) + { + Emu.Quit(true); + return 0; + } } else { // Should be unreachable report_fatal_error("RPCS3 initialization failed!"); + return 1; } #ifdef _WIN32 diff --git a/rpcs3/main_application.h b/rpcs3/main_application.h index c60d8b002c..2ac1b64334 100644 --- a/rpcs3/main_application.h +++ b/rpcs3/main_application.h @@ -8,7 +8,7 @@ struct EmuCallbacks; class main_application { public: - virtual void Init() = 0; + virtual bool Init() = 0; static bool InitializeEmulator(const std::string& user, bool force_init, bool show_gui); diff --git a/rpcs3/rpcs3qt/emu_settings.cpp b/rpcs3/rpcs3qt/emu_settings.cpp index f2ee78ca5d..095b291741 100644 --- a/rpcs3/rpcs3qt/emu_settings.cpp +++ b/rpcs3/rpcs3qt/emu_settings.cpp @@ -63,13 +63,27 @@ namespace emu_settings::emu_settings() : 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) { 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 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.SetDefaultGraphicsAdapter(adapter); } -} -emu_settings::~emu_settings() -{ + return true; } void emu_settings::LoadSettings(const std::string& title_id) diff --git a/rpcs3/rpcs3qt/emu_settings.h b/rpcs3/rpcs3qt/emu_settings.h index 7c26ac5770..75f39807d9 100644 --- a/rpcs3/rpcs3qt/emu_settings.h +++ b/rpcs3/rpcs3qt/emu_settings.h @@ -35,6 +35,8 @@ public: emu_settings(); ~emu_settings(); + bool Init(); + /** 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); @@ -75,7 +77,7 @@ public: void SetSetting(emu_settings_type type, const std::string& val); /** 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.*/ microphone_creator m_microphone_creator; diff --git a/rpcs3/rpcs3qt/gui_application.cpp b/rpcs3/rpcs3qt/gui_application.cpp index 8ec65a446a..2b39a5d4d7 100644 --- a/rpcs3/rpcs3qt/gui_application.cpp +++ b/rpcs3/rpcs3qt/gui_application.cpp @@ -50,7 +50,7 @@ gui_application::~gui_application() #endif } -void gui_application::Init() +bool gui_application::Init() { setWindowIcon(QIcon(":/rpcs3.ico")); @@ -58,6 +58,11 @@ void gui_application::Init() m_gui_settings.reset(new gui_settings()); m_persistent_settings.reset(new persistent_settings()); + if (!m_emu_settings->Init()) + { + return false; + } + // Get deprecated active user (before August 2nd 2020) QString active_user = m_gui_settings->GetValue(gui::um_active_user).toString(); @@ -91,9 +96,9 @@ void gui_application::Init() welcome->exec(); } - if (m_main_window) + if (m_main_window && !m_main_window->Init()) { - m_main_window->Init(); + return false; } #ifdef WITH_DISCORD_RPC @@ -103,6 +108,8 @@ void gui_application::Init() discord::initialize(); } #endif + + return true; } void gui_application::SwitchTranslator(QTranslator& translator, const QString& filename, const QString& language_code) diff --git a/rpcs3/rpcs3qt/gui_application.h b/rpcs3/rpcs3qt/gui_application.h index c954c5a23a..4216717fe1 100644 --- a/rpcs3/rpcs3qt/gui_application.h +++ b/rpcs3/rpcs3qt/gui_application.h @@ -39,7 +39,7 @@ public: } /** Call this method before calling app.exec */ - void Init() override; + bool Init() override; std::unique_ptr get_gs_frame(); diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index dde52db6a7..021af237c6 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -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). * Simplifies logic a bit. */ -void main_window::Init() +bool main_window::Init() { setAcceptDrops(true); @@ -127,7 +127,7 @@ void main_window::Init() 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); } #endif + + return true; } QString main_window::GetCurrentTitle() diff --git a/rpcs3/rpcs3qt/main_window.h b/rpcs3/rpcs3qt/main_window.h index b35ca3c81a..13323a9ddf 100644 --- a/rpcs3/rpcs3qt/main_window.h +++ b/rpcs3/rpcs3qt/main_window.h @@ -81,7 +81,7 @@ class main_window : public QMainWindow public: explicit main_window(std::shared_ptr gui_settings, std::shared_ptr emu_settings, std::shared_ptr persistent_settings, QWidget *parent = 0); - void Init(); + bool Init(); ~main_window(); QIcon GetAppIcon(); diff --git a/rpcs3/rpcs3qt/render_creator.cpp b/rpcs3/rpcs3qt/render_creator.cpp index 3f803dd651..a63bae0f96 100644 --- a/rpcs3/rpcs3qt/render_creator.cpp +++ b/rpcs3/rpcs3qt/render_creator.cpp @@ -77,7 +77,10 @@ render_creator::render_creator(QObject *parent) : QObject(parent) enum_thread.detach(); if (button != QMessageBox::Ignore) - std::exit(1); + { + abort_requested = true; + return; + } supports_vulkan = false; } diff --git a/rpcs3/rpcs3qt/render_creator.h b/rpcs3/rpcs3qt/render_creator.h index 58718231ea..8203f09bb8 100644 --- a/rpcs3/rpcs3qt/render_creator.h +++ b/rpcs3/rpcs3qt/render_creator.h @@ -11,6 +11,10 @@ class render_creator : public QObject Q_OBJECT public: + render_creator(QObject* parent); + + void update_names(const QStringList& names); + struct render_info { QString name; @@ -31,14 +35,11 @@ public: , has_msaa(has_msaa) {} }; + bool abort_requested = false; bool supports_vulkan = false; QStringList vulkan_adapters; render_info Vulkan; render_info OpenGL; render_info NullRender; std::vector renderers; - - render_creator(QObject *parent); - - void update_names(const QStringList& names); };