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
This commit is contained in:
Glenn Rice 2011-02-25 21:14:13 +00:00
parent eef715b1cf
commit 992f8be5b0
17 changed files with 53 additions and 96 deletions

View File

@ -86,7 +86,7 @@ public:
virtual unsigned int PeekMessages() = 0; virtual unsigned int PeekMessages() = 0;
virtual void Initialize() = 0; virtual bool Initialize(void *&) = 0;
virtual void Shutdown() = 0; virtual void Shutdown() = 0;
virtual void DoState(PointerWrap &p) = 0; virtual void DoState(PointerWrap &p) = 0;

View File

@ -120,7 +120,6 @@ bool BootCore(const std::string& _rFilename)
} }
// Run the game // Run the game
StartUp.hMainWindow = Host_GetRenderHandle();
// Init the core // Init the core
if (!Core::Init()) if (!Core::Init())
{ {

View File

@ -215,13 +215,16 @@ bool Init()
GetData<u8>("IPL.AR")); GetData<u8>("IPL.AR"));
} }
// _CoreParameter.hMainWindow is first the m_Panel handle, // g_pWindowHandle is first the m_Panel handle,
// then it is updated to have the new window handle, // then it is updated to the render window handle,
// within g_video_backend->Initialize() // within g_video_backend->Initialize()
// TODO: that's ugly, change Initialize() to take m_Panel g_pWindowHandle = Host_GetRenderHandle();
// and return the new window handle if (!g_video_backend->Initialize(g_pWindowHandle))
g_video_backend->Initialize(); {
g_pWindowHandle = _CoreParameter.hMainWindow; emuThreadGoing.Shutdown();
Host_SetWaitCursor(false);
return false;
}
HW::Init(); HW::Init();
DSP::GetDSPEmulator()->Initialize(g_pWindowHandle, DSP::GetDSPEmulator()->Initialize(g_pWindowHandle,

View File

@ -31,7 +31,7 @@
#include "Core.h" // for bWii #include "Core.h" // for bWii
SCoreStartupParameter::SCoreStartupParameter() SCoreStartupParameter::SCoreStartupParameter()
: hInstance(0), hMainWindow(0), : hInstance(0),
bJITNoBlockCache(false), bJITBlockLinking(true), bJITNoBlockCache(false), bJITBlockLinking(true),
bJITOff(false), bJITOff(false),
bJITLoadStoreOff(false), bJITLoadStorelXzOff(false), bJITLoadStoreOff(false), bJITLoadStorelXzOff(false),

View File

@ -69,9 +69,6 @@ struct SCoreStartupParameter
{ {
void* hInstance; // HINSTANCE but we don't want to include <windows.h> void* hInstance; // HINSTANCE but we don't want to include <windows.h>
// Windows/GUI related
void* hMainWindow;
// Settings // Settings
bool bEnableDebugging; bool bEnableDebugging;
bool bAutomaticStart; bool bAutomaticStart;

View File

@ -9,7 +9,7 @@ namespace DX11
class VideoBackend : public VideoBackendHLE class VideoBackend : public VideoBackendHLE
{ {
void Initialize(); bool Initialize(void *&);
void Shutdown(); void Shutdown();
std::string GetName(); std::string GetName();

View File

@ -52,11 +52,6 @@
namespace DX11 namespace DX11
{ {
void*& VideoWindowHandle()
{
return SConfig::GetInstance().m_LocalCoreStartupParameter.hMainWindow;
}
unsigned int VideoBackend::PeekMessages() unsigned int VideoBackend::PeekMessages()
{ {
MSG msg; MSG msg;
@ -158,7 +153,7 @@ void VideoBackend::ShowConfig(void *_hParent)
#endif #endif
} }
void VideoBackend::Initialize() bool VideoBackend::Initialize(void *&window_handle)
{ {
InitBackendInfo(); InitBackendInfo();
@ -169,15 +164,17 @@ void VideoBackend::Initialize()
UpdateProjectionHack(g_Config.iPhackvalue, g_Config.sPhackvalue); UpdateProjectionHack(g_Config.iPhackvalue, g_Config.sPhackvalue);
UpdateActiveConfig(); UpdateActiveConfig();
VideoWindowHandle() = (void*)EmuWindow::Create((HWND)VideoWindowHandle(), GetModuleHandle(0), _T("Loading - Please wait.")); window_handle = (void*)EmuWindow::Create((HWND)window_handle, GetModuleHandle(0), _T("Loading - Please wait."));
if (VideoWindowHandle() == NULL) if (window_handle == NULL)
{ {
ERROR_LOG(VIDEO, "An error has occurred while trying to create the window."); ERROR_LOG(VIDEO, "An error has occurred while trying to create the window.");
return; return false;
} }
OSD::AddMessage("Dolphin Direct3D11 Video Backend.", 5000); OSD::AddMessage("Dolphin Direct3D11 Video Backend.", 5000);
s_BackendInitialized = true; s_BackendInitialized = true;
return true;
} }
void VideoBackend::Video_Prepare() void VideoBackend::Video_Prepare()

View File

@ -9,7 +9,7 @@ namespace DX9
class VideoBackend : public VideoBackendHLE class VideoBackend : public VideoBackendHLE
{ {
void Initialize(); bool Initialize(void *&);
void Shutdown(); void Shutdown();
std::string GetName(); std::string GetName();

View File

@ -60,11 +60,6 @@
namespace DX9 namespace DX9
{ {
void*& VideoWindowHandle()
{
return SConfig::GetInstance().m_LocalCoreStartupParameter.hMainWindow;
}
unsigned int VideoBackend::PeekMessages() unsigned int VideoBackend::PeekMessages()
{ {
MSG msg; MSG msg;
@ -138,7 +133,7 @@ void VideoBackend::ShowConfig(void* parent)
#endif #endif
} }
void VideoBackend::Initialize() bool VideoBackend::Initialize(void *&window_handle)
{ {
InitBackendInfo(); 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 UpdateProjectionHack(g_Config.iPhackvalue, g_Config.sPhackvalue); // DX9 projection hack could be disabled by commenting out this line
UpdateActiveConfig(); UpdateActiveConfig();
VideoWindowHandle() = (void*)EmuWindow::Create((HWND)VideoWindowHandle(), GetModuleHandle(0), _T("Loading - Please wait.")); window_handle = (void*)EmuWindow::Create((HWND)window_handle, GetModuleHandle(0), _T("Loading - Please wait."));
if (VideoWindowHandle() == NULL) if (window_handle == NULL)
{ {
ERROR_LOG(VIDEO, "An error has occurred while trying to create the window."); ERROR_LOG(VIDEO, "An error has occurred while trying to create the window.");
return; return false;
} }
else if (FAILED(DX9::D3D::Init())) 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); 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); OSD::AddMessage("Dolphin Direct3D9 Video Backend.", 5000);
s_BackendInitialized = true; s_BackendInitialized = true;
return true;
} }
void VideoBackend::Video_Prepare() void VideoBackend::Video_Prepare()

View File

@ -82,11 +82,6 @@ void OpenGL_SetWindowText(const char *text)
#endif #endif
} }
static void*& VideoWindowHandle()
{
return SConfig::GetInstance().m_LocalCoreStartupParameter.hMainWindow;
}
namespace OGL namespace OGL
{ {
@ -320,7 +315,7 @@ void XEventThread()
// Create rendering window. // Create rendering window.
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize() // 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; int _tx, _ty, _twidth, _theight;
Core::Callback_VideoGetWindowSize(_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; s_backbuffer_height = _theight;
#if defined(USE_WX) && USE_WX #if defined(USE_WX) && USE_WX
GLWin.panel = (wxPanel *)VideoWindowHandle(); GLWin.panel = (wxPanel *)window_handle;
GLWin.glCanvas = new wxGLCanvas(GLWin.panel, wxID_ANY, NULL, GLWin.glCanvas = new wxGLCanvas(GLWin.panel, wxID_ANY, NULL,
wxPoint(0, 0), wxSize(_twidth, _theight)); wxPoint(0, 0), wxSize(_twidth, _theight));
GLWin.glCanvas->Show(true); GLWin.glCanvas->Show(true);
@ -364,7 +359,6 @@ bool OpenGL_Create(int _iwidth, int _iheight)
style |= NSResizableWindowMask | NSTitledWindowMask; style |= NSResizableWindowMask | NSTitledWindowMask;
} }
(void)VideoWindowHandle;
GLWin.cocoaWin = [[NSWindow alloc] initWithContentRect: size GLWin.cocoaWin = [[NSWindow alloc] initWithContentRect: size
styleMask: style backing: NSBackingStoreBuffered defer: NO]; styleMask: style backing: NSBackingStoreBuffered defer: NO];
if (GLWin.cocoaWin == nil) { if (GLWin.cocoaWin == nil) {
@ -381,8 +375,8 @@ bool OpenGL_Create(int _iwidth, int _iheight)
[GLWin.cocoaWin makeKeyAndOrderFront: nil]; [GLWin.cocoaWin makeKeyAndOrderFront: nil];
#elif defined(_WIN32) #elif defined(_WIN32)
VideoWindowHandle() = (void*)EmuWindow::Create((HWND)VideoWindowHandle(), GetModuleHandle(0), _T("Please wait...")); window_handle = (void*)EmuWindow::Create((HWND)window_handle, GetModuleHandle(0), _T("Please wait..."));
if (VideoWindowHandle() == NULL) if (window_handle == NULL)
{ {
Host_SysMessage("failed to create window"); Host_SysMessage("failed to create window");
return false; return false;
@ -466,7 +460,7 @@ bool OpenGL_Create(int _iwidth, int _iheight)
GLWin.dpy = XOpenDisplay(0); GLWin.dpy = XOpenDisplay(0);
GLWin.evdpy = XOpenDisplay(0); GLWin.evdpy = XOpenDisplay(0);
GLWin.parent = (Window)VideoWindowHandle(); GLWin.parent = (Window)window_handle;
GLWin.screen = DefaultScreen(GLWin.dpy); GLWin.screen = DefaultScreen(GLWin.dpy);
if (GLWin.parent == 0) if (GLWin.parent == 0)
GLWin.parent = RootWindow(GLWin.dpy, GLWin.screen); GLWin.parent = RootWindow(GLWin.dpy, GLWin.screen);
@ -510,7 +504,7 @@ bool OpenGL_Create(int _iwidth, int _iheight)
GLWin.height = _theight; GLWin.height = _theight;
CreateXWindow(); CreateXWindow();
VideoWindowHandle() = (void *)GLWin.win; window_handle = (void *)GLWin.win;
#endif #endif
return true; return true;
} }

View File

@ -84,7 +84,7 @@ extern GLWindow GLWin;
// Public OpenGL util // Public OpenGL util
// Initialization / upkeep // Initialization / upkeep
bool OpenGL_Create(int _width, int _height); bool OpenGL_Create(void *&);
void OpenGL_Shutdown(); void OpenGL_Shutdown();
void OpenGL_Update(); void OpenGL_Update();
bool OpenGL_MakeCurrent(); bool OpenGL_MakeCurrent();

View File

@ -9,7 +9,7 @@ namespace OGL
class VideoBackend : public VideoBackendHLE class VideoBackend : public VideoBackendHLE
{ {
void Initialize(); bool Initialize(void *&);
void Shutdown(); void Shutdown();
std::string GetName(); std::string GetName();

View File

@ -157,7 +157,7 @@ void VideoBackend::ShowConfig(void *_hParent)
#endif #endif
} }
void VideoBackend::Initialize() bool VideoBackend::Initialize(void *&window_handle)
{ {
InitBackendInfo(); InitBackendInfo();
@ -170,11 +170,13 @@ void VideoBackend::Initialize()
UpdateActiveConfig(); UpdateActiveConfig();
if (!OpenGL_Create(640, 480)) if (!OpenGL_Create(window_handle))
return; return false;
OSD::AddMessage("Dolphin OpenGL Video Backend.", 5000); OSD::AddMessage("Dolphin OpenGL Video Backend.", 5000);
s_BackendInitialized = true; s_BackendInitialized = true;
return true;
} }
// This is called after Initialize() from the Core // This is called after Initialize() from the Core

View File

@ -16,7 +16,6 @@
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Common.h" #include "Common.h"
#include "Core.h"
#include "../../Plugin_VideoOGL/Src/GLUtil.h" #include "../../Plugin_VideoOGL/Src/GLUtil.h"
#include "SWRenderer.h" #include "SWRenderer.h"
@ -31,11 +30,6 @@ RasterFont* s_pfont = NULL;
void SWRenderer::Init() 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() void SWRenderer::Shutdown()

View File

@ -39,6 +39,7 @@
#include "FileUtil.h" #include "FileUtil.h"
#include "VideoBackend.h" #include "VideoBackend.h"
#include "../../../Core/VideoCommon/Src/Fifo.h" #include "../../../Core/VideoCommon/Src/Fifo.h"
#include "Core.h"
namespace SW namespace SW
{ {
@ -62,10 +63,16 @@ void VideoBackend::ShowConfig(void *_hParent)
#endif #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()); 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(); InitBPMemory();
InitXFMemory(); InitXFMemory();
SWCommandProcessor::Init(); SWCommandProcessor::Init();
@ -76,6 +83,8 @@ void VideoBackend::Initialize()
HwRasterizer::Init(); HwRasterizer::Init();
SWRenderer::Init(); SWRenderer::Init();
DebugUtil::Init(); DebugUtil::Init();
return true;
} }
void VideoBackend::DoState(PointerWrap&) void VideoBackend::DoState(PointerWrap&)

View File

@ -9,7 +9,7 @@ namespace SW
class VideoBackend : public VideoBackendLLE class VideoBackend : public VideoBackendLLE
{ {
void Initialize(); bool Initialize(void *&);
void Shutdown(); void Shutdown();
std::string GetName(); std::string GetName();

View File

@ -43,11 +43,6 @@ WNDCLASSEX wndClass;
const TCHAR m_szClassName[] = _T("DolphinEmuWnd"); const TCHAR m_szClassName[] = _T("DolphinEmuWnd");
int g_winstyle; 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 /* Invisible cursor option. In the lack of a predefined IDC_BLANK we make
an empty transparent cursor */ 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)); CreateCursors(/*m_hInstance*/GetModuleHandle(0));
// Create child window // 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, WS_CHILD,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
parent, NULL, hInstance, NULL); parent, NULL, hInstance, NULL);
ShowWindow(m_hWnd, SW_SHOWMAXIMIZED); 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
}
return m_hWnd; return m_hWnd;
} }