From 992f8be5b0ac4c391e50bb2e18cb2f7df1b7dd26 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Fri, 25 Feb 2011 21:14:13 +0000 Subject: [PATCH] If video backend initialization fails, have the emulator die gracefully instead of crashing the application. Also a little clean up of the passage of the video window handle to the backend and back. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7248 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/VideoBackendBase.h | 2 +- Source/Core/Core/Src/BootManager.cpp | 1 - Source/Core/Core/Src/Core.cpp | 15 ++++--- Source/Core/Core/Src/CoreParameter.cpp | 2 +- Source/Core/Core/Src/CoreParameter.h | 3 -- .../Plugin_VideoDX11/Src/VideoBackend.h | 2 +- Source/Plugins/Plugin_VideoDX11/Src/main.cpp | 15 +++---- .../Plugin_VideoDX9/Src/VideoBackend.h | 2 +- Source/Plugins/Plugin_VideoDX9/Src/main.cpp | 17 ++++---- Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp | 18 +++----- Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h | 2 +- .../Plugin_VideoOGL/Src/VideoBackend.h | 2 +- Source/Plugins/Plugin_VideoOGL/Src/main.cpp | 8 ++-- .../Plugin_VideoSoftware/Src/SWRenderer.cpp | 6 --- .../Plugin_VideoSoftware/Src/SWmain.cpp | 11 ++++- .../Plugin_VideoSoftware/Src/VideoBackend.h | 2 +- .../Plugin_VideoSoftware/Src/Win32.cpp | 41 ++----------------- 17 files changed, 53 insertions(+), 96 deletions(-) diff --git a/Source/Core/Common/Src/VideoBackendBase.h b/Source/Core/Common/Src/VideoBackendBase.h index c72a8a2cc9..e18e2a6acd 100644 --- a/Source/Core/Common/Src/VideoBackendBase.h +++ b/Source/Core/Common/Src/VideoBackendBase.h @@ -86,7 +86,7 @@ public: virtual unsigned int PeekMessages() = 0; - virtual void Initialize() = 0; + virtual bool Initialize(void *&) = 0; virtual void Shutdown() = 0; virtual void DoState(PointerWrap &p) = 0; diff --git a/Source/Core/Core/Src/BootManager.cpp b/Source/Core/Core/Src/BootManager.cpp index 80a6127c56..e857ad82ca 100644 --- a/Source/Core/Core/Src/BootManager.cpp +++ b/Source/Core/Core/Src/BootManager.cpp @@ -120,7 +120,6 @@ bool BootCore(const std::string& _rFilename) } // Run the game - StartUp.hMainWindow = Host_GetRenderHandle(); // Init the core if (!Core::Init()) { diff --git a/Source/Core/Core/Src/Core.cpp b/Source/Core/Core/Src/Core.cpp index cca835751d..6f8b0a38df 100644 --- a/Source/Core/Core/Src/Core.cpp +++ b/Source/Core/Core/Src/Core.cpp @@ -215,13 +215,16 @@ bool Init() GetData("IPL.AR")); } - // _CoreParameter.hMainWindow is first the m_Panel handle, - // then it is updated to have the new window handle, + // g_pWindowHandle is first the m_Panel handle, + // then it is updated to the render window handle, // within g_video_backend->Initialize() - // TODO: that's ugly, change Initialize() to take m_Panel - // and return the new window handle - g_video_backend->Initialize(); - g_pWindowHandle = _CoreParameter.hMainWindow; + g_pWindowHandle = Host_GetRenderHandle(); + if (!g_video_backend->Initialize(g_pWindowHandle)) + { + emuThreadGoing.Shutdown(); + Host_SetWaitCursor(false); + return false; + } HW::Init(); DSP::GetDSPEmulator()->Initialize(g_pWindowHandle, diff --git a/Source/Core/Core/Src/CoreParameter.cpp b/Source/Core/Core/Src/CoreParameter.cpp index ec32a13ac0..986476815f 100644 --- a/Source/Core/Core/Src/CoreParameter.cpp +++ b/Source/Core/Core/Src/CoreParameter.cpp @@ -31,7 +31,7 @@ #include "Core.h" // for bWii SCoreStartupParameter::SCoreStartupParameter() -: hInstance(0), hMainWindow(0), +: hInstance(0), bJITNoBlockCache(false), bJITBlockLinking(true), bJITOff(false), bJITLoadStoreOff(false), bJITLoadStorelXzOff(false), diff --git a/Source/Core/Core/Src/CoreParameter.h b/Source/Core/Core/Src/CoreParameter.h index 2faba2f78e..188ec63a10 100644 --- a/Source/Core/Core/Src/CoreParameter.h +++ b/Source/Core/Core/Src/CoreParameter.h @@ -69,9 +69,6 @@ struct SCoreStartupParameter { void* hInstance; // HINSTANCE but we don't want to include - // Windows/GUI related - void* hMainWindow; - // Settings bool bEnableDebugging; bool bAutomaticStart; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VideoBackend.h b/Source/Plugins/Plugin_VideoDX11/Src/VideoBackend.h index 3493a4b74d..7f33dfeb3a 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/VideoBackend.h +++ b/Source/Plugins/Plugin_VideoDX11/Src/VideoBackend.h @@ -9,7 +9,7 @@ namespace DX11 class VideoBackend : public VideoBackendHLE { - void Initialize(); + bool Initialize(void *&); void Shutdown(); std::string GetName(); diff --git a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp index b1ee66bda0..9fc36929b3 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp @@ -52,11 +52,6 @@ namespace DX11 { -void*& VideoWindowHandle() -{ - return SConfig::GetInstance().m_LocalCoreStartupParameter.hMainWindow; -} - unsigned int VideoBackend::PeekMessages() { MSG msg; @@ -158,7 +153,7 @@ void VideoBackend::ShowConfig(void *_hParent) #endif } -void VideoBackend::Initialize() +bool VideoBackend::Initialize(void *&window_handle) { InitBackendInfo(); @@ -169,15 +164,17 @@ void VideoBackend::Initialize() UpdateProjectionHack(g_Config.iPhackvalue, g_Config.sPhackvalue); UpdateActiveConfig(); - VideoWindowHandle() = (void*)EmuWindow::Create((HWND)VideoWindowHandle(), GetModuleHandle(0), _T("Loading - Please wait.")); - if (VideoWindowHandle() == NULL) + window_handle = (void*)EmuWindow::Create((HWND)window_handle, GetModuleHandle(0), _T("Loading - Please wait.")); + if (window_handle == NULL) { ERROR_LOG(VIDEO, "An error has occurred while trying to create the window."); - return; + return false; } OSD::AddMessage("Dolphin Direct3D11 Video Backend.", 5000); s_BackendInitialized = true; + + return true; } void VideoBackend::Video_Prepare() diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VideoBackend.h b/Source/Plugins/Plugin_VideoDX9/Src/VideoBackend.h index 05c21952b6..59ca3a870b 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VideoBackend.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/VideoBackend.h @@ -9,7 +9,7 @@ namespace DX9 class VideoBackend : public VideoBackendHLE { - void Initialize(); + bool Initialize(void *&); void Shutdown(); std::string GetName(); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp index 340d72f80c..e6cc6c3b11 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp @@ -60,11 +60,6 @@ namespace DX9 { -void*& VideoWindowHandle() -{ - return SConfig::GetInstance().m_LocalCoreStartupParameter.hMainWindow; -} - unsigned int VideoBackend::PeekMessages() { MSG msg; @@ -138,7 +133,7 @@ void VideoBackend::ShowConfig(void* parent) #endif } -void VideoBackend::Initialize() +bool VideoBackend::Initialize(void *&window_handle) { InitBackendInfo(); @@ -149,20 +144,22 @@ void VideoBackend::Initialize() UpdateProjectionHack(g_Config.iPhackvalue, g_Config.sPhackvalue); // DX9 projection hack could be disabled by commenting out this line UpdateActiveConfig(); - VideoWindowHandle() = (void*)EmuWindow::Create((HWND)VideoWindowHandle(), GetModuleHandle(0), _T("Loading - Please wait.")); - if (VideoWindowHandle() == NULL) + window_handle = (void*)EmuWindow::Create((HWND)window_handle, GetModuleHandle(0), _T("Loading - Please wait.")); + if (window_handle == NULL) { ERROR_LOG(VIDEO, "An error has occurred while trying to create the window."); - return; + return false; } else if (FAILED(DX9::D3D::Init())) { MessageBox(GetActiveWindow(), _T("Unable to initialize Direct3D. Please make sure that you have the latest version of DirectX 9.0c correctly installed."), _T("Fatal Error"), MB_ICONERROR|MB_OK); - return; + return false; } OSD::AddMessage("Dolphin Direct3D9 Video Backend.", 5000); s_BackendInitialized = true; + + return true; } void VideoBackend::Video_Prepare() diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp index cd0ea26872..46140b4e7b 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp @@ -82,11 +82,6 @@ void OpenGL_SetWindowText(const char *text) #endif } -static void*& VideoWindowHandle() -{ - return SConfig::GetInstance().m_LocalCoreStartupParameter.hMainWindow; -} - namespace OGL { @@ -320,7 +315,7 @@ void XEventThread() // Create rendering window. // Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize() -bool OpenGL_Create(int _iwidth, int _iheight) +bool OpenGL_Create(void *&window_handle) { int _tx, _ty, _twidth, _theight; Core::Callback_VideoGetWindowSize(_tx, _ty, _twidth, _theight); @@ -330,7 +325,7 @@ bool OpenGL_Create(int _iwidth, int _iheight) s_backbuffer_height = _theight; #if defined(USE_WX) && USE_WX - GLWin.panel = (wxPanel *)VideoWindowHandle(); + GLWin.panel = (wxPanel *)window_handle; GLWin.glCanvas = new wxGLCanvas(GLWin.panel, wxID_ANY, NULL, wxPoint(0, 0), wxSize(_twidth, _theight)); GLWin.glCanvas->Show(true); @@ -364,7 +359,6 @@ bool OpenGL_Create(int _iwidth, int _iheight) style |= NSResizableWindowMask | NSTitledWindowMask; } - (void)VideoWindowHandle; GLWin.cocoaWin = [[NSWindow alloc] initWithContentRect: size styleMask: style backing: NSBackingStoreBuffered defer: NO]; if (GLWin.cocoaWin == nil) { @@ -381,8 +375,8 @@ bool OpenGL_Create(int _iwidth, int _iheight) [GLWin.cocoaWin makeKeyAndOrderFront: nil]; #elif defined(_WIN32) - VideoWindowHandle() = (void*)EmuWindow::Create((HWND)VideoWindowHandle(), GetModuleHandle(0), _T("Please wait...")); - if (VideoWindowHandle() == NULL) + window_handle = (void*)EmuWindow::Create((HWND)window_handle, GetModuleHandle(0), _T("Please wait...")); + if (window_handle == NULL) { Host_SysMessage("failed to create window"); return false; @@ -466,7 +460,7 @@ bool OpenGL_Create(int _iwidth, int _iheight) GLWin.dpy = XOpenDisplay(0); GLWin.evdpy = XOpenDisplay(0); - GLWin.parent = (Window)VideoWindowHandle(); + GLWin.parent = (Window)window_handle; GLWin.screen = DefaultScreen(GLWin.dpy); if (GLWin.parent == 0) GLWin.parent = RootWindow(GLWin.dpy, GLWin.screen); @@ -510,7 +504,7 @@ bool OpenGL_Create(int _iwidth, int _iheight) GLWin.height = _theight; CreateXWindow(); - VideoWindowHandle() = (void *)GLWin.win; + window_handle = (void *)GLWin.win; #endif return true; } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h index 735b0f4731..c82edc0eb8 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.h @@ -84,7 +84,7 @@ extern GLWindow GLWin; // Public OpenGL util // Initialization / upkeep -bool OpenGL_Create(int _width, int _height); +bool OpenGL_Create(void *&); void OpenGL_Shutdown(); void OpenGL_Update(); bool OpenGL_MakeCurrent(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VideoBackend.h b/Source/Plugins/Plugin_VideoOGL/Src/VideoBackend.h index c529c58639..ae54806a73 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VideoBackend.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/VideoBackend.h @@ -9,7 +9,7 @@ namespace OGL class VideoBackend : public VideoBackendHLE { - void Initialize(); + bool Initialize(void *&); void Shutdown(); std::string GetName(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp index 97e5692a0e..01989efc94 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp @@ -157,7 +157,7 @@ void VideoBackend::ShowConfig(void *_hParent) #endif } -void VideoBackend::Initialize() +bool VideoBackend::Initialize(void *&window_handle) { InitBackendInfo(); @@ -170,11 +170,13 @@ void VideoBackend::Initialize() UpdateActiveConfig(); - if (!OpenGL_Create(640, 480)) - return; + if (!OpenGL_Create(window_handle)) + return false; OSD::AddMessage("Dolphin OpenGL Video Backend.", 5000); s_BackendInitialized = true; + + return true; } // This is called after Initialize() from the Core diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp index 276628bf4c..3923ed0840 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp @@ -16,7 +16,6 @@ // http://code.google.com/p/dolphin-emu/ #include "Common.h" -#include "Core.h" #include "../../Plugin_VideoOGL/Src/GLUtil.h" #include "SWRenderer.h" @@ -31,11 +30,6 @@ RasterFont* s_pfont = NULL; void SWRenderer::Init() { - if (!OpenGL_Create(640, 480)) // 640x480 will be the default if all else fails - { - Core::Callback_VideoLog("SWRenderer::Create failed\n"); - return; - } } void SWRenderer::Shutdown() diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/SWmain.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/SWmain.cpp index 04a3b4ecc6..52d080b9a9 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/SWmain.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/SWmain.cpp @@ -39,6 +39,7 @@ #include "FileUtil.h" #include "VideoBackend.h" #include "../../../Core/VideoCommon/Src/Fifo.h" +#include "Core.h" namespace SW { @@ -62,10 +63,16 @@ void VideoBackend::ShowConfig(void *_hParent) #endif } -void VideoBackend::Initialize() +bool VideoBackend::Initialize(void *&window_handle) { g_SWVideoConfig.Load((std::string(File::GetUserPath(D_CONFIG_IDX)) + "gfx_software.ini").c_str()); + if (!OpenGL_Create(window_handle)) + { + Core::Callback_VideoLog("SWRenderer::Create failed\n"); + return false; + } + InitBPMemory(); InitXFMemory(); SWCommandProcessor::Init(); @@ -76,6 +83,8 @@ void VideoBackend::Initialize() HwRasterizer::Init(); SWRenderer::Init(); DebugUtil::Init(); + + return true; } void VideoBackend::DoState(PointerWrap&) diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/VideoBackend.h b/Source/Plugins/Plugin_VideoSoftware/Src/VideoBackend.h index 1e02131a48..cbaa68c56b 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/VideoBackend.h +++ b/Source/Plugins/Plugin_VideoSoftware/Src/VideoBackend.h @@ -9,7 +9,7 @@ namespace SW class VideoBackend : public VideoBackendLLE { - void Initialize(); + bool Initialize(void *&); void Shutdown(); std::string GetName(); diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/Win32.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/Win32.cpp index b6288c95bb..8b756102c9 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/Win32.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/Win32.cpp @@ -43,11 +43,6 @@ WNDCLASSEX wndClass; const TCHAR m_szClassName[] = _T("DolphinEmuWnd"); int g_winstyle; -static void*& VideoWindowHandle() -{ - return SConfig::GetInstance().m_LocalCoreStartupParameter.hMainWindow; -} - // ------------------------------------------ /* Invisible cursor option. In the lack of a predefined IDC_BLANK we make an empty transparent cursor */ @@ -206,44 +201,14 @@ HWND OpenWindow(HWND parent, HINSTANCE hInstance, int width, int height, const T CreateCursors(/*m_hInstance*/GetModuleHandle(0)); // Create child window - if (parent) - { - m_hParent = parent; + m_hParent = parent; - m_hWnd = CreateWindow(m_szClassName, title, + m_hWnd = CreateWindow(m_szClassName, title, WS_CHILD, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, hInstance, NULL); - ShowWindow(m_hWnd, SW_SHOWMAXIMIZED); - } - - // Create new separate window - else - { - DWORD style = g_SWVideoConfig.bFullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW; - - RECT rc = {0, 0, width, height}; - AdjustWindowRect(&rc, style, false); - - int w = rc.right - rc.left; - int h = rc.bottom - rc.top; - - rc.left = (1280 - w)/2; - rc.right = rc.left + w; - rc.top = (1024 - h)/2; - rc.bottom = rc.top + h; - - m_hParent = (HWND)VideoWindowHandle(); - - m_hWnd = CreateWindow(m_szClassName, title, - style, - rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, - parent, NULL, hInstance, NULL ); - - g_winstyle = GetWindowLong( m_hWnd, GWL_STYLE ); - g_winstyle &= ~WS_MAXIMIZE & ~WS_MINIMIZE; // remove minimize/maximize style - } + ShowWindow(m_hWnd, SW_SHOWMAXIMIZED); return m_hWnd; }