Skip to main content
gamedev.net
🔒 Locked

Cannot reset device

Started by Uriel 13 replies 2.9k views
Original Post
Uriel
Uriel
I tried to add DEVICELOST support in my game, but Reset returns fail and i dont know what to do now. Before calling Reset on device i release all textures/surfaces/VB that uses D3DPOOL_DEFAULT memory. I also make sure that im in D3DERR_DEVICENOTRESET state. I have never done lost device handling before so im not sure what else should i release.. i have stencil shadows, env bumpmaps (i release render targets i use for env maps), DirectSound (i dont release anything here). Please shed some light on me...
Uriel
Uriel
After checking what stateblocks are, i can assure you that i dont use them.

I also didnt create any additional swap chains.
I do use stencil buffer but i dont create any stencil surface..
superpig
superpig
Which error code does it return? There are five possibles, according to the DXSDK:

quote:


  • D3DERR_DEVICELOST : The device has been lost but cannot be reset at this time. Therefore, rendering is not possible.
  • D3DERR_DRIVERINTERNALERROR : Internal driver error. Applications should generally shut down when receiving this error.
  • D3DERR_INVALIDCALL : The method call is invalid. For example, a method''s parameter may have an invalid value.
  • D3DERR_OUTOFVIDEOMEMORY : Direct3D does not have enough display memory to perform the operation.
  • E_OUTOFMEMORY : Direct3D could not allocate sufficient memory to complete the call.


Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse
__Daedalus__
__Daedalus__
Do you use ID3DXFont? If so it needs to be released and reset when you reset your deivce. It has its own methods OnLostDevice() and OnResetDevice().
__Daedalus__
__Daedalus__
Also ID3DXMesh. If you use that but don''t create it with type D3DXMESH_MANAGED then you''ll need to recreate it.
Uriel
Uriel
@__Daedalus__:

Now i call OnDeviceLost on fonts and my mesh manager loads meshes with D3DXMESH_MANAGED option. However Reset() still fails.
There are few TextMeshes that i create using D3DXCreateText. Im not sure what memory they allocate..

@ superpig:

The problem is, it does not return any of those.. in docs it is said that those are just some of possible errors..

@Anonymous Poster:

I just turned debug on in dx for my first time (i coded for a year and i had no clue that there is smth like that - no comments) and my app crashes. Even if debug lvl is set to lowest, when i run app it halts on code where i create render target surface..
Uriel
Uriel
eh.. now i even release those meshes created using D3DXCreateText, and still Reset() fails..
superpig
superpig
quote:
Original post by Uriel
@ superpig:

The problem is, it does not return any of those.. in docs it is said that those are just some of possible errors..


For such a thing to happen is extremely rare... still, if it wasn''t one of those, then what was it? Get the HRESULT that it returns, and then feed that into the "DirectX Error Lookup" program that comes with the SDK.
Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse
Uriel
Uriel
After enabling dxdebug it turned out that dx is ''idiotenaparat'' after all.. i had many stupid bugs in code but it compiled under retail d3d and was running without problems.

Now all is corrected, but still Reset() fails. But now i get this from debug:

Direct3D9: (ERROR) :The following D3DPOOL_DEFAULT surfaces/buffers/textures still exist
Direct3D9: (ERROR) : D3DRTYPE_SURFACE
Direct3D9: (ERROR) : D3DRTYPE_TEXTURE
[...] // many more textures here
Direct3D9: (ERROR) : D3DRTYPE_TEXTURE
Direct3D9: (ERROR) : D3DRTYPE_VERTEXBUFFER
Direct3D9: (ERROR) : D3DRTYPE_VERTEXBUFFER
Direct3D9: (ERROR) : D3DRTYPE_VERTEXBUFFER
Direct3D9: (ERROR) : D3DRTYPE_SURFACE
Direct3D9: (ERROR) :All user created D3DPOOL_DEFAULT surfaces must be freed before Reset can succeed. Reset Fails.
Unhandled exception at 0x77f813b1 in dupa.exe: User breakpoint.

I have all textures in one place, and all are D3DPOOL_MANAGED.. same thing with VertexBuffers. I release surfaces before calling Reset() (same thing with VertexBuffers).
Axiverse
Axiverse
Are you sure that it needs to be reset?

For ex. When a fullscreen app gets minimized, the device gets lost, but you don''t want to reset until, it exits the minimized state...
Uriel
Uriel
Yes, im sure it has to be reseted since TestCooperativeLevel() returns D3DERR_DEVICELOST. For example when i mninimalize my fullscreen app to taskbar, it loses focus and device is lost. Then i test in loop until i encounter DEVICENORESET state, then i release all POOL_DEFAULT res and i call Reset().

Now here is the funny part: sometimes when i trigger DEVICELOST by pressing [ctrl alt del] or [alt tab] TestCooperativeLevel() somehow returns D3D_OK and app enters render loop - and crashes in random place inside.
Sometimes it detects DEVICELOST properly but crashes inside
Reset() and dx debug says that it was due to unfreed POOL_DEFAULT textures/surfaces/meshes. But i release _all_ textures/surfaces/meshes (even those not POOL_DEFAULT) i use just before calling Reset().

I dont think its normal since according to docs it should ''silently fail'' and render grey screen, not crash..
Namethatnobodyelsetook
Namethatnobodyelsetook
This might actually be indicative of more problems throughout your code. Are you sure you get/release and correctly?

Every time you GetSurfaceLevel on a texture, you need to release the surface. Every time you GetRenderTarget or GetDepthStencilSurface, you need to release the surface. If you''ve somehow kept something locked, your release for Reset won''t actually free the texture/vb.
Uriel
Uriel
How very true.. most errors where in my water surface rendering, where i render to texture.. i deleted whole code and ill rewrite it later.

Now i can reset device properly.
Thank you all for help

And i have another question :>

When in fullscreen, if i [ALT TAB] device is reseted properly.
But if press [CTRL ALT DEL] i get memory write exception and app crashes in random place. It happens only when i use lights.

Is there a difference between loosing device with ALT TAB and CTRL ALT DEL ? And why light has smth to do with it?

Ed: it crashes on that line:
lpD3DDevice->EndScene();
if just before it i call TestCooperativeLevel() it crashes on Test..



[edited by - Uriel on April 17, 2004 5:03:20 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.