I am making a game engine and I am going to support both OpenGL and Direct2D. I heard that rendertargets can return an error on EndDraw(), needing to recreate every resource created with it. I was wondering if that happens frequently, should I handle that error and how does it happen. In OpenGL you don't lose a context just because so. So, what causes the loss of a render target and should I use direct2D for games even with this problem? Thanks in advance.
1 Answers
In the past (read DirectX 9 and earlier), a lost device usually occurred when you switched focus away from a full screen application. Then, during the time that your application was not visible, you had no graphics device to draw to. And when the focus was set back to your application, you had to re-initialize the device and all resources that were created on that device.
Today (DirectX 10 and beyond), this is not the case anymore. Access to the graphics device is virtualized, so you keep your device handle when the application loses focus. However, there are still a few cases when you can loose your device, e.g., physical changes to the computer, crash and reset of the driver, etc. So, the situations in which you loose your device are very rare and somewhat extreme. You can handle those situations if you want (and you should if you want to create a stable application), but the average user will most likely not run into any of these extreme situations. For more information, take a look at this MSDN article.

- 32,049
- 4
- 39
- 70
-
Thanks. Before, I got kinda scared because you could lose your context frequently but now I am releived. Before, I had read this article (http://www.cplusplus.com/forum/windows/94800/) and I thought I was only going to support OpenGL. Now I can support the best performing one or both. Thanks again. Direct2D is only Vista+ support so I won't need to worry with DX9. – A cool programmer Aug 28 '18 at 15:53
-
@Acoolprogrammer: Not intending to make you worried but apparently Nico was a little too optimistic about lost devices on DirectX 10 and beyond. On my Windows 7 system running DirectX 11 lost devices happen all the time and can clearly be reproduced. All I have to do is hit CTRL+ALT+DEL to open the Windows 7 control screen. As soon as I do this, `EndDraw` returns `D2DERR_RECREATE_TARGET` which means that all device dependent resources have to be re-created... – Andreas Oct 11 '20 at 19:46