exception handling

This commit is contained in:
Glenn Maynard
2004-11-30 20:26:30 +00:00
parent 6f46898f69
commit 07acc3fad4
3 changed files with 92 additions and 105 deletions
+28 -29
View File
@@ -202,12 +202,19 @@ const RageDisplay::PixelFormatDesc *RageDisplay_D3D::GetPixelFormatDesc(PixelFor
RageDisplay_D3D::RageDisplay_D3D( VideoModeParams p ) RageDisplay_D3D::RageDisplay_D3D()
{
}
#define D3D_NOT_INSTALLED \
"DirectX 8.1 or greater is not installed. You can download it from:\n" \
"http://www.microsoft.com/downloads/details.aspx?FamilyID=a19bed22-0b25-4e5d-a584-6389d8a3dad0&displaylang=en"
CString RageDisplay_D3D::Init( VideoModeParams p )
{ {
GraphicsWindow::Initialize(); GraphicsWindow::Initialize();
try
{
LOG->Trace( "RageDisplay_D3D::RageDisplay_D3D()" ); LOG->Trace( "RageDisplay_D3D::RageDisplay_D3D()" );
LOG->MapLog("renderer", "Current renderer: Direct3D"); LOG->MapLog("renderer", "Current renderer: Direct3D");
@@ -218,13 +225,13 @@ RageDisplay_D3D::RageDisplay_D3D( VideoModeParams p )
#else #else
g_D3D8_Module = LoadLibrary("D3D8.dll"); g_D3D8_Module = LoadLibrary("D3D8.dll");
if(!g_D3D8_Module) if(!g_D3D8_Module)
throw RageException_D3DNotInstalled(); return D3D_NOT_INSTALLED;
pDirect3DCreate8 = (Direct3DCreate8_t) GetProcAddress(g_D3D8_Module, "Direct3DCreate8"); pDirect3DCreate8 = (Direct3DCreate8_t) GetProcAddress(g_D3D8_Module, "Direct3DCreate8");
if(!pDirect3DCreate8) if(!pDirect3DCreate8)
{ {
LOG->Trace( "Direct3DCreate8 not found" ); LOG->Trace( "Direct3DCreate8 not found" );
throw RageException_D3DNotInstalled(); return D3D_NOT_INSTALLED;
} }
#endif #endif
@@ -232,11 +239,13 @@ RageDisplay_D3D::RageDisplay_D3D( VideoModeParams p )
if(!g_pd3d) if(!g_pd3d)
{ {
LOG->Trace( "Direct3DCreate8 failed" ); LOG->Trace( "Direct3DCreate8 failed" );
throw RageException_D3DNotInstalled(); return D3D_NOT_INSTALLED;
} }
if( FAILED( g_pd3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &g_DeviceCaps) ) ) if( FAILED( g_pd3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &g_DeviceCaps) ) )
throw RageException_D3DNoAcceleration(); return
"Your system is reporting that Direct3D hardware acceleration is not available. "
"Please obtain an updated driver from your video card manufacturer.\n\n";
D3DADAPTER_IDENTIFIER8 identifier; D3DADAPTER_IDENTIFIER8 identifier;
g_pd3d->GetAdapterIdentifier( D3DADAPTER_DEFAULT, 0, &identifier ); g_pd3d->GetAdapterIdentifier( D3DADAPTER_DEFAULT, 0, &identifier );
@@ -269,28 +278,7 @@ RageDisplay_D3D::RageDisplay_D3D( VideoModeParams p )
* as possible, because if we have to shut it down again we'll flash a window * as possible, because if we have to shut it down again we'll flash a window
* briefly. */ * briefly. */
bool bIgnore = false; bool bIgnore = false;
CString sError = SetVideoMode( p, bIgnore ); return SetVideoMode( p, bIgnore );
if( sError != "" )
RageException::ThrowNonfatal( sError );
} catch(...) {
// Clean up; ~RageDisplay will not be called.
if( g_pd3d )
{
g_pd3d->Release();
g_pd3d = NULL;
}
#if !defined(XBOX)
if( g_D3D8_Module )
{
FreeLibrary( g_D3D8_Module );
g_D3D8_Module = NULL;
}
#endif
GraphicsWindow::Shutdown();
throw;
}
} }
void RageDisplay_D3D::Update(float fDeltaTime) void RageDisplay_D3D::Update(float fDeltaTime)
@@ -302,9 +290,20 @@ RageDisplay_D3D::~RageDisplay_D3D()
{ {
LOG->Trace( "RageDisplay_D3D::~RageDisplay()" ); LOG->Trace( "RageDisplay_D3D::~RageDisplay()" );
if( g_pd3dDevice )
g_pd3dDevice->Release(); g_pd3dDevice->Release();
if( g_pd3d )
g_pd3d->Release(); g_pd3d->Release();
#if !defined(XBOX)
if( g_D3D8_Module )
{
FreeLibrary( g_D3D8_Module );
g_D3D8_Module = NULL;
}
#endif
GraphicsWindow::Shutdown(); GraphicsWindow::Shutdown();
} }
+4 -16
View File
@@ -1,26 +1,14 @@
/* RageDisplay_D3D - Direct3D renderer. */
#ifndef RAGEDISPLAY_D3D_H #ifndef RAGEDISPLAY_D3D_H
#define RAGEDISPLAY_D3D_H #define RAGEDISPLAY_D3D_H
class RageException_D3DNotInstalled: public exception
{
const char *what() const { return
"DirectX 8.1 or greater is not installed. You can download it from:\n"
"http://www.microsoft.com/downloads/details.aspx?FamilyID=a19bed22-0b25-4e5d-a584-6389d8a3dad0&displaylang=en"; }
};
class RageException_D3DNoAcceleration: public exception
{
const char *what() const { return
"Your system is reporting that Direct3D hardware acceleration is not available. "
"Please obtain an updated driver from your video card manufacturer.\n\n"; }
};
class RageDisplay_D3D: public RageDisplay class RageDisplay_D3D: public RageDisplay
{ {
public: public:
RageDisplay_D3D( VideoModeParams params ); RageDisplay_D3D();
~RageDisplay_D3D(); ~RageDisplay_D3D();
CString Init( VideoModeParams p );
void Update(float fDeltaTime); void Update(float fDeltaTime);
void ResolutionChanged(); void ResolutionChanged();
+6 -6
View File
@@ -717,12 +717,12 @@ RageDisplay *CreateDisplay()
else if( sRenderer.CompareNoCase("d3d")==0 ) else if( sRenderer.CompareNoCase("d3d")==0 )
{ {
#if defined(SUPPORT_D3D) #if defined(SUPPORT_D3D)
error += "Initializing Direct3D...\n"; RageDisplay_D3D *pRet = new RageDisplay_D3D;
try { CString sError = pRet->Init( params );
return new RageDisplay_D3D( params ); if( sError == "" )
} catch( const exception &e ) { return pRet;
error += CString(e.what()) + "\n"; error += "Initializing Direct3D...\n" + sError;
}; delete pRet;
#endif #endif
} }
else if( sRenderer.CompareNoCase("null")==0 ) else if( sRenderer.CompareNoCase("null")==0 )