{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/Win2D/issues/194","labels_url":"https://api.github.com/repos/Microsoft/Win2D/issues/194/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/Win2D/issues/194/comments","events_url":"https://api.github.com/repos/Microsoft/Win2D/issues/194/events","html_url":"https://github.com/Microsoft/Win2D/issues/194","id":120188419,"number":194,"title":"DeviceLost on a CanvasVirtualControl","user":{"login":"ErwanJes","id":1706728,"avatar_url":"https://avatars.githubusercontent.com/u/1706728?v=3","gravatar_id":"","url":"https://api.github.com/users/ErwanJes","html_url":"https://github.com/ErwanJes","followers_url":"https://api.github.com/users/ErwanJes/followers","following_url":"https://api.github.com/users/ErwanJes/following{/other_user}","gists_url":"https://api.github.com/users/ErwanJes/gists{/gist_id}","starred_url":"https://api.github.com/users/ErwanJes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ErwanJes/subscriptions","organizations_url":"https://api.github.com/users/ErwanJes/orgs","repos_url":"https://api.github.com/users/ErwanJes/repos","events_url":"https://api.github.com/users/ErwanJes/events{/privacy}","received_events_url":"https://api.github.com/users/ErwanJes/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/Win2D/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2015-12-03T14:53:27Z","updated_at":"2015-12-09T14:12:00Z","closed_at":"2015-12-07T17:48:28Z","body":"I have a simple CanvasVirtualControl :\r\n```xaml\r\n<canvas:CanvasVirtualControl x:Name=\"canvas\" />\r\n```\r\n\r\n```c#\r\ncanvas.RegionsInvalidated += OnRegionsInvalidated;\r\n...\r\nprivate void OnRegionsInvalidated(CanvasVirtualControl sender, CanvasRegionsInvalidatedEventArgs args)\r\n{\r\n      foreach (var region in args.InvalidatedRegions)\r\n      {\r\n        try\r\n        {\r\n          using (var session = sender.CreateDrawingSession(region))\r\n          {\r\n          }\r\n        }\r\n        catch (Exception ex)\r\n        {\r\n         sender.Device.IsDeviceLost(ex.HResult); // == True !\r\n        }\r\n    }\r\n}\r\n\r\n```\r\n\r\nWhen the device wake up from sleep (or suspended mode), there is a call to `OnRegionsInvalidated` which crash in `sender.CreateDrawingSession(region)`.\r\nEven though we catch the exception, there is a infinite loop there.\r\n\r\nIs there a way to properly handle DeviceLost ?\r\n\r\nPS : I read the doc http://microsoft.github.io/Win2D/html/HandlingDeviceLost.htm but did not find a solution.\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/Win2D/issues/comments/163248800","html_url":"https://github.com/Microsoft/Win2D/issues/194#issuecomment-163248800","issue_url":"https://api.github.com/repos/Microsoft/Win2D/issues/194","id":163248800,"user":{"login":"ErwanJes","id":1706728,"avatar_url":"https://avatars.githubusercontent.com/u/1706728?v=3","gravatar_id":"","url":"https://api.github.com/users/ErwanJes","html_url":"https://github.com/ErwanJes","followers_url":"https://api.github.com/users/ErwanJes/followers","following_url":"https://api.github.com/users/ErwanJes/following{/other_user}","gists_url":"https://api.github.com/users/ErwanJes/gists{/gist_id}","starred_url":"https://api.github.com/users/ErwanJes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ErwanJes/subscriptions","organizations_url":"https://api.github.com/users/ErwanJes/orgs","repos_url":"https://api.github.com/users/ErwanJes/repos","events_url":"https://api.github.com/users/ErwanJes/events{/privacy}","received_events_url":"https://api.github.com/users/ErwanJes/received_events","type":"User","site_admin":false},"created_at":"2015-12-09T14:12:00Z","updated_at":"2015-12-09T14:12:00Z","body":"To continue with this issue, sometimes after a resume, there is no callback `RegionsInvalidated` after a `canvas.Invalidate(rect)`.\r\n\r\nI do not know if this is link to the previous problem but I think so.\r\n\r\nWith Win2D in Debug, `imageSource` is null, so nothing is fired.\r\n```C++\r\nIFACEMETHODIMP CanvasVirtualControl::InvalidateRegion(Rect region)\r\n{\r\n    return ExceptionBoundary(\r\n        [&]\r\n        {\r\n            auto imageSource = GetCurrentRenderTarget()->Target;\r\n            // imageSource = nullptr\r\n            if (imageSource)\r\n                ThrowIfFailed(imageSource->InvalidateRegion(region));\r\n        });\r\n}\r\n```\r\nI still cannot repro this in a small sample :/"}}