DX9/DX11: Fixing some maybe possible crashes if a game was started, the config dialog opened and the game closed again. Due to other issues this still happens quite often though...

Various warning fixes.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6684 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
NeoBrainX 2010-12-29 13:07:00 +00:00
parent 603c99f64f
commit 07d947c834
7 changed files with 44 additions and 17 deletions

View File

@ -158,7 +158,7 @@ void CMixer::PushSamples(short *samples, unsigned int num_samples)
if (m_sampleRate == 32000)
Common::AtomicAdd(m_numSamples, num_samples);
else if (m_sampleRate == 48000)
Common::AtomicAdd(m_numSamples, num_samples * 1.5);
Common::AtomicAdd(m_numSamples, num_samples * 3 / 2);
else
PanicAlert("Mixer: Unsupported sample rate.");

View File

@ -158,7 +158,7 @@ bool XAudio2::Start()
void XAudio2::SetVolume(int volume)
{
//linear 1- .01
m_volume = (float)volume / 100.0;
m_volume = (float)volume / 100.f;
if (pMasteringVoice)
pMasteringVoice->SetVolume(m_volume);

View File

@ -29,14 +29,17 @@ D3DX11COMPILEFROMMEMORYTYPE PD3DX11CompileFromMemory = NULL;
D3DX11FILTERTEXTURETYPE PD3DX11FilterTexture = NULL;
D3DX11SAVETEXTURETOFILEATYPE PD3DX11SaveTextureToFileA = NULL;
D3DX11SAVETEXTURETOFILEWTYPE PD3DX11SaveTextureToFileW = NULL;
int d3dx_dll_ref = 0;
CREATEDXGIFACTORY PCreateDXGIFactory = NULL;
HINSTANCE hDXGIDll = NULL;
int dxgi_dll_ref = 0;
typedef HRESULT (WINAPI* D3D11CREATEDEVICEANDSWAPCHAIN)(IDXGIAdapter*, D3D_DRIVER_TYPE, HMODULE, UINT, CONST D3D_FEATURE_LEVEL*, UINT, UINT, CONST DXGI_SWAP_CHAIN_DESC*, IDXGISwapChain**, ID3D11Device**, D3D_FEATURE_LEVEL*, ID3D11DeviceContext**);
D3D11CREATEDEVICE PD3D11CreateDevice = NULL;
D3D11CREATEDEVICEANDSWAPCHAIN PD3D11CreateDeviceAndSwapChain = NULL;
HINSTANCE hD3DDll = NULL;
int d3d_dll_ref = 0;
namespace D3D
{
@ -65,11 +68,14 @@ bool bFrameInProgress = false;
HRESULT LoadDXGI()
{
if (dxgi_dll_ref++ > 0) return S_OK;
if (hDXGIDll) return S_OK;
hDXGIDll = LoadLibraryA("dxgi.dll");
if (!hDXGIDll)
{
MessageBoxA(NULL, "Failed to load dxgi.dll", "Critical error", MB_OK | MB_ICONERROR);
--dxgi_dll_ref;
return E_FAIL;
}
PCreateDXGIFactory = (CREATEDXGIFACTORY)GetProcAddress(hDXGIDll, "CreateDXGIFactory");
@ -80,11 +86,14 @@ HRESULT LoadDXGI()
HRESULT LoadD3D()
{
if (d3d_dll_ref++ > 0) return S_OK;
if (hD3DDll) return S_OK;
hD3DDll = LoadLibraryA("d3d11.dll");
if (!hD3DDll)
{
MessageBoxA(NULL, "Failed to load d3d11.dll", "Critical error", MB_OK | MB_ICONERROR);
--d3d_dll_ref;
return E_FAIL;
}
PD3D11CreateDevice = (D3D11CREATEDEVICE)GetProcAddress(hD3DDll, "D3D11CreateDevice");
@ -98,6 +107,7 @@ HRESULT LoadD3D()
HRESULT LoadD3DX()
{
if (d3dx_dll_ref++ > 0) return S_OK;
if (hD3DXDll) return S_OK;
// try to load D3DX11 first to check whether we have proper runtime support
@ -135,6 +145,9 @@ HRESULT LoadD3DX()
void UnloadDXGI()
{
if (!dxgi_dll_ref) return;
if (--dxgi_dll_ref != 0) return;
if(hDXGIDll) FreeLibrary(hDXGIDll);
hDXGIDll = NULL;
PCreateDXGIFactory = NULL;
@ -142,6 +155,9 @@ void UnloadDXGI()
void UnloadD3DX()
{
if (!d3dx_dll_ref) return;
if (--d3dx_dll_ref != 0) return;
if(hD3DXDll) FreeLibrary(hD3DXDll);
hD3DXDll = NULL;
PD3DX11FilterTexture = NULL;
@ -151,6 +167,9 @@ void UnloadD3DX()
void UnloadD3D()
{
if (!d3d_dll_ref) return;
if (--d3d_dll_ref != 0) return;
if(hD3DDll) FreeLibrary(hD3DDll);
hD3DDll = NULL;
PD3D11CreateDevice = NULL;

View File

@ -27,7 +27,7 @@ D3DBlob::D3DBlob(ID3D10Blob* d3dblob) : ref(1)
{
blob = d3dblob;
data = (u8*)blob->GetBufferPointer();
size = blob->GetBufferSize();
size = (unsigned int)blob->GetBufferSize();
d3dblob->AddRef();
}

View File

@ -167,7 +167,7 @@ void DllConfig(void *_hParent)
if (SUCCEEDED(hr)) hr = D3D::LoadD3D();
if (FAILED(hr))
{
if (!s_PluginInitialized) D3D::UnloadDXGI();
D3D::UnloadDXGI();
return;
}
@ -212,11 +212,8 @@ void DllConfig(void *_hParent)
diag->ShowModal();
diag->Destroy();
if (!s_PluginInitialized)
{
D3D::UnloadDXGI();
D3D::UnloadD3D();
}
D3D::UnloadDXGI();
D3D::UnloadD3D();
#endif
}

View File

@ -26,10 +26,12 @@ HINSTANCE hD3DXDll = NULL;
D3DXSAVESURFACETOFILEATYPE PD3DXSaveSurfaceToFileA = NULL;
D3DXSAVETEXTURETOFILEATYPE PD3DXSaveTextureToFileA = NULL;
D3DXCOMPILESHADERTYPE PD3DXCompileShader = NULL;
int d3dx_dll_ref = 0;
typedef IDirect3D9* (WINAPI* DIRECT3DCREATE9)(UINT);
DIRECT3DCREATE9 PDirect3DCreate9 = NULL;
HINSTANCE hD3DDll = NULL;
int d3d_dll_ref = 0;
namespace D3D
{
@ -93,6 +95,8 @@ bool IsATIDevice()
HRESULT Init()
{
if (d3d_dll_ref++ > 0) return S_OK;
hD3DDll = LoadLibraryA("d3d9.dll");
if (!hD3DDll)
{
@ -105,15 +109,20 @@ HRESULT Init()
// Create the D3D object, which is needed to create the D3DDevice.
D3D = PDirect3DCreate9(D3D_SDK_VERSION);
if (!D3D)
{
--d3d_dll_ref;
return E_FAIL;
}
Enumerate();
return S_OK;
}
void Shutdown()
{
if(D3D)
D3D->Release();
if (!d3d_dll_ref) return;
if (--d3d_dll_ref != 0) return;
if (D3D) D3D->Release();
D3D = NULL;
if (hD3DDll) FreeLibrary(hD3DDll);
@ -278,6 +287,8 @@ void Enumerate()
// we're first trying to load the dll Dolphin was compiled with, otherwise the most up-to-date one
HRESULT LoadD3DX9()
{
if (d3dx_dll_ref++ > 0) return S_OK;
HRESULT hr = E_FAIL;
hD3DXDll = LoadLibraryA(StringFromFormat("d3dx9_%d.dll", D3DX_SDK_VERSION).c_str());
if (hD3DXDll != NULL)
@ -326,6 +337,7 @@ HRESULT LoadD3DX9()
return S_OK;
fail:
--d3dx_dll_ref;
FreeLibrary(hD3DXDll);
PD3DXCompileShader = NULL;
PD3DXSaveSurfaceToFileA = NULL;
@ -335,6 +347,9 @@ fail:
void UnloadD3DX9()
{
if (!d3dx_dll_ref) return;
if (--d3dx_dll_ref != 0) return;
FreeLibrary(hD3DXDll);
PD3DXCompileShader = NULL;
PD3DXSaveSurfaceToFileA = NULL;

View File

@ -165,10 +165,7 @@ void DllConfig(void *_hParent)
{
#if defined(HAVE_WX) && HAVE_WX
InitBackendInfo();
// If not initialized, only init D3D so we can enumerate resolutions.
if (!s_PluginInitialized)
D3D::Init();
D3D::Init();
// adapters
g_Config.backend_info.Adapters.clear();
@ -190,8 +187,7 @@ void DllConfig(void *_hParent)
diag->ShowModal();
diag->Destroy();
if (!s_PluginInitialized)
D3D::Shutdown();
D3D::Shutdown();
#endif
}