From 0039eab8782a483901e7085c79f40f02c2b95d94 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 26 Sep 2014 21:16:56 -0700 Subject: [PATCH] Offer to toggle graphics backends on any failure. So, even if Direct3D 9 fails. --- Windows/EmuThread.cpp | 34 +++++++++++++++++++++++++++++++--- Windows/OpenGLBase.cpp | 2 +- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index e1f70f4fd9..27ef8b92c4 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -3,11 +3,13 @@ #include "base/timeutil.h" #include "base/NativeApp.h" #include "base/mutex.h" +#include "i18n/i18n.h" #include "util/text/utf8.h" #include "Common/Log.h" #include "Common/StringUtils.h" #include "../Globals.h" #include "Windows/EmuThread.h" +#include "Windows/W32Util/Misc.h" #include "Windows/WndMainWindow.h" #include "Windows/resource.h" #include "Core/Reporting.h" @@ -126,12 +128,38 @@ unsigned int WINAPI TheThread(void *) std::string error_string; if (!host->InitGraphics(&error_string)) { + I18NCategory *err = GetI18NCategory("Error"); Reporting::ReportMessage("Graphics init error: %s", error_string.c_str()); - std::string full_error = StringFromFormat( "Failed initializing OpenGL. Try upgrading your graphics drivers.\n\nError message:\n\n%s", error_string.c_str()); - MessageBox(0, ConvertUTF8ToWString(full_error).c_str(), L"OpenGL Error", MB_OK | MB_ICONERROR); + + const char *defaultErrorOpenGL = "Failed initializing graphics. Try upgrading your graphics drivers.\n\nWould you like to try switching to DirectX 9?\n\nError message:"; + const char *defaultErrorDirect3D9 = "Failed initializing graphics. Try upgrading your graphics drivers.\n\nWould you like to try switching to OpenGL?\n\nError message:"; + const char *genericError; + int nextBackend = GPU_BACKEND_DIRECT3D9; + switch (g_Config.iGPUBackend) { + case GPU_BACKEND_DIRECT3D9: + nextBackend = GPU_BACKEND_OPENGL; + genericError = err->T("GenericDirect3D9Error", defaultErrorDirect3D9); + break; + case GPU_BACKEND_OPENGL: + default: + nextBackend = GPU_BACKEND_DIRECT3D9; + genericError = err->T("GenericOpenGLError", defaultErrorOpenGL); + break; + } + std::string full_error = StringFromFormat("%s\n\n%s", genericError, error_string.c_str()); + std::wstring title = ConvertUTF8ToWString(err->T("GenericGraphicsError", "Graphics Error")); + bool yes = IDYES == MessageBox(0, ConvertUTF8ToWString(full_error).c_str(), title.c_str(), MB_ICONERROR | MB_YESNO); ERROR_LOG(BOOT, full_error.c_str()); - // No safe way out without OpenGL. + if (yes) { + // Change the config to the alternative and restart. + g_Config.iGPUBackend = nextBackend; + g_Config.Save(); + + W32Util::ExitAndRestart(); + } + + // No safe way out without graphics. ExitProcess(1); } diff --git a/Windows/OpenGLBase.cpp b/Windows/OpenGLBase.cpp index ca77511688..97a97506b6 100644 --- a/Windows/OpenGLBase.cpp +++ b/Windows/OpenGLBase.cpp @@ -162,7 +162,7 @@ bool GL_Init(HWND window, std::string *error_message) { } // Avoid further error messages. Let's just bail, it's safe, and we can't continue. - ExitProcess(0); + ExitProcess(1); } if (GLEW_OK != glewInit()) {