Archived

This topic is now archived and is closed to further replies.

Christoph

Testcooperativeevel???

Recommended Posts

Hi, I implemented a Device-Lost-protection using Testcooperativelevel; when device is lost the applications enters a loop until the device is available again. The problem is that, even If I switch to my fullscreen-window again, the loop isn''t left - for some reason the device is still lost... How can I detect when the user reenters the apllication, so that I can reset the device??? Thx

Share this post


Link to post
Share on other sites
I don''t think you should rely on WM_ACTIVATE *alone*. You should always TestCooperativeLevel() until you get a D3DERR_DEVICENOTRESET. Only then you should restore.

What does your loop look like?

Muhammad Haggag,
Optimize

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Well, unfortunately, I''m using VB .NET, but I think you''ll be able to understand this:

Engine.TestStatus returns FALSE when TestCooperativeLevel failed, otherwise TRUE.

Engine.Reset (which is never called because the application is stuck in the loop) resets the device.

Application.DoEvents lets the app "breathe", i.e. reveive events.

If Not Engine.TestStatus Then
Do
Try
Application.DoEvents()
Catch ex As Exception
End Try
Loop Until Engine.TestStatus
Engine.Reset()
End If

This is Engine.TestStatus:

Public Function TestStatus() As Boolean
Try
d3dDev.TestCooperativeLevel()
Return True
Catch ex As Exception
Return False
End Try
End Function

Share this post


Link to post
Share on other sites
Check for Success/Fail of TestCooperativeLevel is not sufficient. You have to check the exception that gets thrown.
C#:

catch(D3D.DeviceLostException){
//Device is lost, free all non-MANAGED resources
//Sleep for a bit to not waste resources
}catch(D3D.DeviceNotResetException){
//Device can be reset now
}


Both of those are a failure, but DeviceNotResetException is what you''re waiting for. If TestCooperativeLevel succeeds it means that everything is fine and no Reseting is needed.


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites