Dear all,

In my current project, I extract some texture colors to define player colors, etc. While running it on my Win10 PC (Intel i5, Nvidia GTX 750), all is fine and works as expected. Running it on a Win 7 Sp1 (Intel i5, Nvidia GTX 1060) setup, it crashes with the following exception:

SharpDX.SharpDXException: HRESULT: [0x887A0005], Module: [SharpDX.DXGI], ApiCode: [DXGI_ERROR_DEVICE_REMOVED/DeviceRemoved], Message: Unknown
   at SharpDX.Result.CheckError()
   at SharpDX.Direct3D11.DeviceContext.MapSubresource(Resource resourceRef, Int32 subresource, MapMode mapType, MapFlags mapFlags)
   at SharpDX.Direct3D11.DeviceContext.MapSubresource(Texture2D resource, Int32 mipSlice, Int32 arraySlice, MapMode mode, MapFlags flags, DataStream& stream)
   at SharpDX.Direct3D11.DeviceContext.MapSubresource(Resource resource, Int32 subresource, MapMode mode, MapFlags flags, DataStream& stream)
   at Microsoft.Xna.Framework.Graphics.Texture2D.PlatformGetData[T](Int32 level, Int32 arraySlice, Rectangle rect, T[] data, Int32 startIndex, Int32 elementCount)
   at Microsoft.Xna.Framework.Graphics.Texture2D.GetData[T](T[] data)

I tried to catch it and work around it, but no success so far. The few hints I found in this direction were either not answered (link) or pointed towards overclocking issues or old sets of drivers (link). I checked the overclocking issue (not the case) and of course updated to the newest set of drivers.

Would you have any idea what the problem could be? Thanks for your input!

Maybe check scaling and size of image and different resolution results and if GetData sampling data outside bounds?
Might be able to get something from d3dDevice->GetDeviceRemovedReason() too if all else fails.

Hi @AlienScribble,

How would I call this? GraphicsDevice does not seem to have this function built in. Am I looking at the wrong object?


I found two interesting sources about the subject: Microsoft and GitHub. I will see if I can get some answers there.

After having done some more reading, I am still not sure how to approach this. But it seems to be a current issue (#6265) for the next MonoGame release.

I will try to somehow fix it. But I doubt that I am skilled enough to contribute to fixing issue #6265. @nkast, @KonajuGames Since you were in the discussion about the issue, could you maybe help me out with some hints on how to approach this? Do I need to check every draw call for this exception?

Catching the exception at a higher level inside BeginDraw() / Draw() / EndDraw() would be easier IMO. That would be a huge undertaking, as you will then need to dispose and recreate every resource (States, ContentManagers, VertexBuffers).
If you are targeting the windows desktop perhaps you could use XNA which handles those things better but it’s a pain to install the XNA SDK in modern windows and VS.

Thanks for the heads up, @nkast! As I mentioned earlier, I believe that this undertaking is seriously overreaching my skills. So, first, I think I will play around and try to get a work around going. If that does not work, I will try to dig deeper into recreating the resources.

I’m not sure how to do it thru MonoGame - but I know that 2 reasons I suspect it might give are:
(could also be: removed, reset, device-lost or driver error)

And perhaps it’s because GetData was done on something that’s outside the actual texture (like if it was 256x256 and tried to access at 550,600)

I’m now wondering if GraphicsDebugMessage could be used to find out the reason.
Like: GraphicsDebugMessage message;
if (gpu.GraphicsDebug.TryDequeueMessage(out message)) { Console.WriteLine(message.Message);}
I’m just guessing - I’ve never tried it. ;p