Working version of the d3d device lost patch. It might need some more working for VBOs, but RTTs are now properly released before reset().

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1624 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2008-10-09 11:23:37 +00:00
parent 3f153d2a2c
commit e8ef136cfe
2 changed files with 64 additions and 43 deletions

View File

@ -398,11 +398,15 @@ bool CD3D8Driver::beginScene(bool backBuffer, bool zBuffer, SColor color,
{ {
if(FAILED(hr = pID3DDevice->TestCooperativeLevel())) if(FAILED(hr = pID3DDevice->TestCooperativeLevel()))
{ {
if (hr == D3DERR_DEVICELOST)
{
Sleep(100);
hr = pID3DDevice->TestCooperativeLevel();
if (hr == D3DERR_DEVICELOST) if (hr == D3DERR_DEVICELOST)
return false; return false;
}
if (hr == D3DERR_DEVICENOTRESET) if ((hr == D3DERR_DEVICENOTRESET) && !reset())
reset();
return false; return false;
} }
} }
@ -433,40 +437,6 @@ bool CD3D8Driver::beginScene(bool backBuffer, bool zBuffer, SColor color,
} }
//! resets the device
bool CD3D8Driver::reset()
{
// reset
HRESULT hr;
os::Printer::log("Resetting D3D8 device.", ELL_INFORMATION);
if (FAILED(hr = pID3DDevice->Reset(&present)))
{
if (hr == D3DERR_DEVICELOST)
{
DeviceLost = true;
os::Printer::log("Resetting failed due to device lost.", ELL_WARNING);
}
else
os::Printer::log("Resetting failed.", ELL_WARNING);
return false;
}
DeviceLost = false;
ResetRenderStates = true;
LastVertexType = (E_VERTEX_TYPE)-1;
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
CurrentTexture[i] = 0;
setVertexShader(EVT_STANDARD);
setRenderStates3DMode();
setFog(FogColor, LinearFog, FogStart, FogEnd, FogDensity, PixelFog, RangeFog);
setAmbientLight(AmbientLight);
return true;
}
//! applications must call this method after performing any rendering. returns false if failed. //! applications must call this method after performing any rendering. returns false if failed.
bool CD3D8Driver::endScene() bool CD3D8Driver::endScene()
{ {
@ -492,18 +462,68 @@ bool CD3D8Driver::endScene()
hr = pID3DDevice->Present(srcRct, NULL, (HWND)WindowId, NULL); hr = pID3DDevice->Present(srcRct, NULL, (HWND)WindowId, NULL);
if (SUCCEEDED(hr))
return true;
if (hr == D3DERR_DEVICELOST) if (hr == D3DERR_DEVICELOST)
{ {
DeviceLost = true; DeviceLost = true;
os::Printer::log("DIRECT3D8 device lost.", ELL_WARNING); os::Printer::log("DIRECT3D8 device lost.", ELL_WARNING);
} }
else else
if (FAILED(hr) && hr != D3DERR_INVALIDCALL)
{
os::Printer::log("DIRECT3D8 present failed.", ELL_WARNING); os::Printer::log("DIRECT3D8 present failed.", ELL_WARNING);
return false; return false;
} }
//! resets the device
bool CD3D8Driver::reset()
{
u32 i;
os::Printer::log("Resetting D3D8 device.", ELL_INFORMATION);
for (i=0; i<Textures.size(); ++i)
{
if (Textures[i].Surface->isRenderTarget())
{
IDirect3DTexture8* tex = ((CD3D8Texture*)(Textures[i].Surface))->getDX8Texture();
if (tex)
tex->Release();
}
}
HRESULT hr = pID3DDevice->Reset(&present);
for (i=0; i<Textures.size(); ++i)
{
if (Textures[i].Surface->isRenderTarget())
((CD3D8Texture*)(Textures[i].Surface))->createRenderTarget();
}
if (FAILED(hr))
{
if (hr == D3DERR_DEVICELOST)
{
DeviceLost = true;
os::Printer::log("Resetting failed due to device lost.", ELL_WARNING);
}
else
os::Printer::log("Resetting failed.", ELL_WARNING);
return false;
}
DeviceLost = false;
ResetRenderStates = true;
LastVertexType = (E_VERTEX_TYPE)-1;
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
CurrentTexture[i] = 0;
setVertexShader(EVT_STANDARD);
setRenderStates3DMode();
setFog(FogColor, LinearFog, FogStart, FogEnd, FogDensity, PixelFog, RangeFog);
setAmbientLight(AmbientLight);
return true; return true;
} }

View File

@ -2245,13 +2245,14 @@ void CD3D9Driver::draw3DLine(const core::vector3df& start,
//! resets the device //! resets the device
bool CD3D9Driver::reset() bool CD3D9Driver::reset()
{ {
u32 i;
os::Printer::log("Resetting D3D9 device.", ELL_INFORMATION); os::Printer::log("Resetting D3D9 device.", ELL_INFORMATION);
for (u32 i=0; i<Textures.size(); ++i) for (i=0; i<Textures.size(); ++i)
{ {
if (Textures[i].Surface->isRenderTarget()) if (Textures[i].Surface->isRenderTarget())
{ {
IDirect3DTexture9 tex = ((CD3D9Texture*)(Textures[i].Surface))->getDX9Texture(); IDirect3DTexture9* tex = ((CD3D9Texture*)(Textures[i].Surface))->getDX9Texture();
if (tex) if (tex)
tex->Release(); tex->Release();
} }
@ -2259,7 +2260,7 @@ bool CD3D9Driver::reset()
HRESULT hr = pID3DDevice->Reset(&present); HRESULT hr = pID3DDevice->Reset(&present);
for (u32 i=0; i<Textures.size(); ++i) for (i=0; i<Textures.size(); ++i)
{ {
if (Textures[i].Surface->isRenderTarget()) if (Textures[i].Surface->isRenderTarget())
((CD3D9Texture*)(Textures[i].Surface))->createRenderTarget(); ((CD3D9Texture*)(Textures[i].Surface))->createRenderTarget();