File tree 2 files changed +20
-1
lines changed
2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,8 @@ public class DXCanvas : Control
36
36
protected int _lastFps = 0 ;
37
37
protected DateTime _lastFpsUpdate = DateTime . UtcNow ;
38
38
39
+ const uint D2DERR_RECREATE_TARGET = 0x8899000C ;
40
+
39
41
#endregion // Internal properties
40
42
41
43
@@ -513,7 +515,23 @@ protected override void OnPaint(PaintEventArgs e)
513
515
_device . BeginDraw ( ) ;
514
516
_device . Clear ( BackColor . ToD3DCOLORVALUE ( ) ) ;
515
517
OnRender ( _graphicsD2d ) ;
516
- _device . EndDraw ( ) ;
518
+
519
+ try
520
+ {
521
+ _device . EndDraw ( ) ;
522
+ }
523
+ catch ( Win32Exception ex )
524
+ {
525
+ // handle device lost
526
+ if ( ex . ErrorCode == unchecked ( ( int ) D2DERR_RECREATE_TARGET ) )
527
+ {
528
+ CreateDevice ( DeviceCreatedReason . DeviceLost ) ;
529
+ }
530
+ else
531
+ {
532
+ throw ;
533
+ }
534
+ }
517
535
}
518
536
519
537
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ public enum DeviceCreatedReason
14
14
{
15
15
FirstTime ,
16
16
UseHardwareAccelerationChanged ,
17
+ DeviceLost ,
17
18
}
18
19
19
20
You can’t perform that action at this time.
0 commit comments