From 4be68dddfbdc7065139351e6e39b5fa97844264a Mon Sep 17 00:00:00 2001 From: LittleWhite Date: Thu, 7 Jan 2016 20:33:54 +0100 Subject: [PATCH] Improve error report from Init() functions Add error popup when citra initialization failed --- src/citra_qt/main.cpp | 50 ++++++++++++++----- src/citra_qt/main.h | 2 + src/core/core.cpp | 3 +- src/core/core.h | 2 +- src/core/loader/loader.cpp | 1 - src/core/system.cpp | 6 ++- src/core/system.h | 9 +++- src/video_core/renderer_base.h | 2 +- .../renderer_opengl/renderer_opengl.cpp | 8 ++- .../renderer_opengl/renderer_opengl.h | 2 +- src/video_core/video_core.cpp | 12 +++-- src/video_core/video_core.h | 2 +- 12 files changed, 72 insertions(+), 27 deletions(-) diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index d2ba3f9dbc..21f4e3a80b 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -248,17 +248,32 @@ void GMainWindow::OnDisplayTitleBars(bool show) } } -void GMainWindow::BootGame(const std::string& filename) { - LOG_INFO(Frontend, "Citra starting..."); - +bool GMainWindow::InitializeSystem() { // Shutdown previous session if the emu thread is still active... if (emu_thread != nullptr) ShutdownGame(); // Initialize the core emulation - System::Init(render_window); + System::Result system_result = System::Init(render_window); + if (System::Result::Success != system_result) { + switch (system_result) { + case System::Result::ErrorInitVideoCore: + QMessageBox::critical(this, tr("Error while starting Citra!"), + tr("Failed to initialize the video core!\n\n" + "Please ensure that your GPU supports OpenGL 3.3 and that you have the latest graphics driver.")); + break; - // Load the game + default: + QMessageBox::critical(this, tr("Error while starting Citra!"), + tr("Unknown error (please check the log)!")); + break; + } + return false; + } + return true; +} + +bool GMainWindow::LoadROM(const std::string& filename) { Loader::ResultStatus result = Loader::LoadFile(filename); if (Loader::ResultStatus::Success != result) { LOG_CRITICAL(Frontend, "Failed to load ROM!"); @@ -269,26 +284,37 @@ void GMainWindow::BootGame(const std::string& filename) { // Build the MessageBox ourselves to have clickable link QMessageBox popup_error; popup_error.setTextFormat(Qt::RichText); - popup_error.setWindowTitle(tr("Error while loading ROM !")); - popup_error.setText(tr("The ROM is probably encrypted !

" - "Please check: https://github.com/citra-emu/citra/wiki/Dumping-Game-Cartridges")); + popup_error.setWindowTitle(tr("Error while loading ROM!")); + popup_error.setText(tr("The game that you are trying to load must be decrypted before being used with Citra.

" + "For more information on dumping and decrypting games, please see: https://citra-emu.org/wiki/Dumping-Game-Cartridges")); popup_error.setIcon(QMessageBox::Critical); popup_error.exec(); break; } case Loader::ResultStatus::ErrorInvalidFormat: - QMessageBox::critical(this, tr("Error while loading ROM !"), + QMessageBox::critical(this, tr("Error while loading ROM!"), tr("The ROM format is not supported.")); break; case Loader::ResultStatus::Error: default: - QMessageBox::critical(this, tr("Error while loading ROM !"), - tr("Unknown error !")); + QMessageBox::critical(this, tr("Error while loading ROM!"), + tr("Unknown error!")); break; } - return; + return false; } + return true; +} + +void GMainWindow::BootGame(const std::string& filename) { + LOG_INFO(Frontend, "Citra starting..."); + + if (!InitializeSystem()) + return; + + if (!LoadROM(filename)) + return; // Create and start the emulation thread emu_thread = Common::make_unique(render_window); diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h index 8c195f8166..945aea0cdf 100644 --- a/src/citra_qt/main.h +++ b/src/citra_qt/main.h @@ -59,6 +59,8 @@ signals: void EmulationStopping(); private: + bool InitializeSystem(); + bool LoadROM(const std::string& filename); void BootGame(const std::string& filename); void ShutdownGame(); diff --git a/src/core/core.cpp b/src/core/core.cpp index 453c7162da..84d6c392ed 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -73,12 +73,11 @@ void Stop() { } /// Initialize the core -int Init() { +void Init() { g_sys_core = Common::make_unique(USER32MODE); g_app_core = Common::make_unique(USER32MODE); LOG_DEBUG(Core, "Initialized OK"); - return 0; } void Shutdown() { diff --git a/src/core/core.h b/src/core/core.h index 453e0a5f06..ad26dca3fa 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -52,7 +52,7 @@ void Halt(const char *msg); void Stop(); /// Initialize the core -int Init(); +void Init(); /// Shutdown the core void Shutdown(); diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 99f1183cac..b1907cd558 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -140,7 +140,6 @@ ResultStatus LoadFile(const std::string& filename) { ResultStatus result = app_loader.Load(); if (ResultStatus::Success == result) { Service::FS::RegisterArchiveType(Common::make_unique(app_loader), Service::FS::ArchiveIdCode::RomFS); - return ResultStatus::Success; } return result; } diff --git a/src/core/system.cpp b/src/core/system.cpp index b62ebf69e3..1e3b2783c2 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -17,14 +17,16 @@ namespace System { -void Init(EmuWindow* emu_window) { +Result Init(EmuWindow* emu_window) { Core::Init(); CoreTiming::Init(); Memory::Init(); HW::Init(); Kernel::Init(); HLE::Init(); - VideoCore::Init(emu_window); + if (!VideoCore::Init(emu_window)) { + return Result::ErrorInitVideoCore; + } AudioCore::Init(); GDBStub::Init(); } diff --git a/src/core/system.h b/src/core/system.h index 59a75ca127..a4a627ea97 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -8,7 +8,14 @@ class EmuWindow; namespace System { -void Init(EmuWindow* emu_window); +enum class Result { + Success, ///< Everything is fine + Error, ///< Something went wrong (no module specified) + ErrorInitCore, ///< Something went wrong during core init + ErrorInitVideoCore, ///< Something went wrong during video core init +}; + +Result Init(EmuWindow* emu_window); void Shutdown(); } diff --git a/src/video_core/renderer_base.h b/src/video_core/renderer_base.h index 506bff8151..91a7b7f179 100644 --- a/src/video_core/renderer_base.h +++ b/src/video_core/renderer_base.h @@ -38,7 +38,7 @@ public: virtual void SetWindow(EmuWindow* window) = 0; /// Initialize the renderer - virtual void Init() = 0; + virtual bool Init() = 0; /// Shutdown the renderer virtual void ShutDown() = 0; diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index ca3a6a6b49..11c4d0daf0 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -445,7 +445,7 @@ static void DebugHandler(GLenum source, GLenum type, GLuint id, GLenum severity, } /// Initialize the renderer -void RendererOpenGL::Init() { +bool RendererOpenGL::Init() { render_window->MakeCurrent(); // TODO: Make frontends initialize this, so they can use gladLoadGLLoader with their own loaders @@ -462,9 +462,15 @@ void RendererOpenGL::Init() { LOG_INFO(Render_OpenGL, "GL_VERSION: %s", glGetString(GL_VERSION)); LOG_INFO(Render_OpenGL, "GL_VENDOR: %s", glGetString(GL_VENDOR)); LOG_INFO(Render_OpenGL, "GL_RENDERER: %s", glGetString(GL_RENDERER)); + if (!GLAD_GL_VERSION_3_3) { + return false; + } + InitOpenGLObjects(); RefreshRasterizerSetting(); + + return true; } /// Shutdown the renderer diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h index b42df7654e..fe4d142a50 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.h +++ b/src/video_core/renderer_opengl/renderer_opengl.h @@ -31,7 +31,7 @@ public: void SetWindow(EmuWindow* window) override; /// Initialize the renderer - void Init() override; + bool Init() override; /// Shutdown the renderer void ShutDown() override; diff --git a/src/video_core/video_core.cpp b/src/video_core/video_core.cpp index 912db91a49..ee5e50df14 100644 --- a/src/video_core/video_core.cpp +++ b/src/video_core/video_core.cpp @@ -28,15 +28,19 @@ std::atomic g_hw_renderer_enabled; std::atomic g_shader_jit_enabled; /// Initialize the video core -void Init(EmuWindow* emu_window) { +bool Init(EmuWindow* emu_window) { Pica::Init(); g_emu_window = emu_window; g_renderer = Common::make_unique(); g_renderer->SetWindow(g_emu_window); - g_renderer->Init(); - - LOG_DEBUG(Render, "initialized OK"); + if (g_renderer->Init()) { + LOG_DEBUG(Render, "initialized OK"); + } else { + LOG_ERROR(Render, "initialization failed !"); + return false; + } + return true; } /// Shutdown the video core diff --git a/src/video_core/video_core.h b/src/video_core/video_core.h index accb0a4eb4..bca67fb8c0 100644 --- a/src/video_core/video_core.h +++ b/src/video_core/video_core.h @@ -41,7 +41,7 @@ extern std::atomic g_shader_jit_enabled; void Start(); /// Initialize the video core -void Init(EmuWindow* emu_window); +bool Init(EmuWindow* emu_window); /// Shutdown the video core void Shutdown();