File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 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
3636 protected int _lastFps = 0 ;
3737 protected DateTime _lastFpsUpdate = DateTime . UtcNow ;
3838
39+ const uint D2DERR_RECREATE_TARGET = 0x8899000C ;
40+
3941 #endregion // Internal properties
4042
4143
@@ -513,7 +515,23 @@ protected override void OnPaint(PaintEventArgs e)
513515 _device . BeginDraw ( ) ;
514516 _device . Clear ( BackColor . ToD3DCOLORVALUE ( ) ) ;
515517 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+ }
517535 }
518536
519537
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ public enum DeviceCreatedReason
1414{
1515 FirstTime ,
1616 UseHardwareAccelerationChanged ,
17+ DeviceLost ,
1718}
1819
1920
You can’t perform that action at this time.
0 commit comments