• 10
• 9
• 12
• 14
• 15

# Device Lost problems

This topic is 4858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, I'm having trouble with a prog i've written. It all works fine until another application obscures the directX target area (its on a picture box). When this happens the mouse moves really slowly. I've added a check to stop calling render if the screen is minimized, which works fine, now I just need a check to see if the directX picutrebox is still visible. So far I have the following code in render:
'My rendering operations
'End the scene
Me.device.EndScene()
Try
Me.device.Present()
Catch ex As Microsoft.DirectX.Direct3D.DeviceLostException
RecoverFromLost()
End Try

and the recoverFromLost function starts with
Dim Code As Int16
While (True)
Me.device.CheckCooperativeLevel(Code)
If Code = Microsoft.DirectX.Direct3D.ResultCode.DeviceNotReset Then
Exit While
End If
End While
'code to reset the device

However this only gets called if ctrl+alt+delete is pressed and always throws the exception
An unhandled exception of type 'System.OverflowException' occurred in 1.exe

Additional information: Arithmetic operation resulted in an overflow.

This points to the CheckCooperativeLevel call. So, does anyone know what calls I need to be making to see if the device should stop rendering (i.e. the draw surface is obscured) and why the checkcooperativeLevel function is overflowing. Many thanks DRB2k2

##### Share on other sites
Might seem a bit obvious, but have you looked at the same framework from the SDK? I always dig into this code as a reference - the guys who wrote the API/samples usually get this stuff right [wink]

I speak from a C++ perspective so this might well be hidden from you in Managed/VB.Net code.

Alternatively, if you can at least read basic C++ code, load up the "empty project" sample from the SDK and do a search for "TestCooperativeLevel" - see how they handle things.

Sorry I can't be more specific than that,
hth
Jack

##### Share on other sites
Hi Jack,
I had a look at the SDK files, but they use the directX helper library. I find this a comlete nightmare to read through. I can understand why MS did it to make the core parts of the samples easier, but it makes the program as a whole a lot more complicated.

Cheers
DRB2k2

##### Share on other sites
Quote:
 Dim Code As Int16...Additional information: Arithmetic operation resulted in an overflow.

I Just read the Device.CheckCooperativeLevel documentation and it seems to say that the [in, out] param (a.k.a. Code) is actually an Int32.

Change this and I'll bet you're fine. The only arithmetic in *your* code is probably contained in CheckCooperativeLevel (I'd expect a type-mismatch error for the if statement). And the function being declared as Int32 and your passing of an Int16 is perfect for an overflow.

Hth
Jack

##### Share on other sites
oh man its always the simple things,
thanks Jack, now I just need to sort out the partially obscured drawing surface problem.
Cheers
DRB2k2

##### Share on other sites
Quote:
 now I just need to sort out the partially obscured drawing surface problem.

There's an old Nvidia driver bug that would cause the system to bog down, including jerky mouse movement, whenever the device window was completely obscured by another window. If that sounds like what you're seeing then you might check and see that you have the latest drivers.