-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GraphicsCaptureItem.Closed Event not firing #17
Comments
Apologies, we've got to update the documentation on that. In order to receive the Closed event, you need to be pumping messages on the thread that creates the You don't need to create a window or anything. Create a |
Thanx, I've managed to get it working. The thing is - I don't have an easily accesable/changable main, so what I've done is:
This ensures I get a working Closed event (as DispatcherQueueController is on same thread as the graphicsCaptureItem) just like you said. The only problem I now have comes from my lack of C++ threading experience. When I get the Closed event I would ideally like to do two things:
will otherwise continue to run and I get some exceptions on the next iteration (iteration after the Closed evnet has been successfully fired and recieved and processed ). So, the question is - is there some safe way to exit the while loop on getting Closed even ? Is there a special msg for Closed, if so a simple:
would be my solution. There is one dirty solution which I use immediately but I am not sure how safe it is:
This works as the loop is iterated exactly two times, one on instantiating it, and second time on closing the CaptureItem. But I am not sure how safe is this solution as I have no Ideal what sort of messages are coming and going, who is sending them and under what conditions... Like you already said, the documentation for using Closed() is maybe not the sharpest pencil in the drawer. |
Ups, I accidentally closed this Issue and I didn't mean to. |
I think you want auto controller = winrt::DispatcherQueueController::CreateOnDedicatedThread();
auto queue = controller.DispatcherQueue();
wil::shared_event initialized(wil::EventOptions::None);
winrt::check_bool(queue.TryEnqueue([=, initialized]()
{
// ...
// Create the item and do stuff with it here
// ...
initialized.SetEvent();
}));
initialized.wait(INFINITE); NOTE: When you want the thread to shut down, call the controller.ShutdownQueueAsync().get(); // Use .get() if you need this to be synchronous,
// otherwise use async as you normally would That will shut down the message pump for that thread. With that said, make sure you're set up to deal with this cross-thread structure. The reason we use the dispatcher queues is to properly marshal back to an expected thread. We can't arbitrarily call back into your thread unless we're given an opportunity (by pumping messages). The setup you've described will mean that the Closed event will fire on the other thread. This may be fine, but I thought it'd mention it for any people in the future that stumble upon this issue. |
If you need to call |
Your suggestion works. Having all inside the lambda:
ensures both events get properly recieved. But, when following your approach, out of some reason, in my function bound to FrameArrived the line_
doesnt seem to work, only black frame gets copied. The size of the windowFrame seems to be correctly copied, but not the content. The content of the window frame is correct (surfacteTexture is ok), its just that the copy seems to not be really working. But maybe I am messing something up, I have to debug everything a bit... EDIT;
works in the effect that it binds both events (FrameArrived and Closed) properly, BUT there seems to be sum problem when using On the other hand, instantiating everything in a seperate function on a new thread like so: |
I think your implementation must have some else going on in regards to the device context behavior your seeing. I'm going to close this issue given that the original problem has been resolved. Good luck! |
Hi,
first of all thank you for making this sample project.
I used your example to create a similar project (C++/Win32) with two notable exceptions:
Create()
but ratherwinrt::Direct3D11CaptureFramePool::CreateFreeThreaded()
andNow the event
OnFrameArrived
works and gets triggered and I am able to use it.But the event
GraphicsCaptureItem.Closed
doesn't get triggered when I close the Window.I bind it like so:
m_itemClosedRevoker = m_item.Closed(winrt::auto_revoke, { this, &MyCapturer::OnCaptureItemClosed });
I also tried just this:
m_item.Closed({ this, &MyCapturer::OnCaptureItemClosed });
I use the preinstalled 3DViewer App as Window for testing.
I know that in your project the
OnCaptureItemClosed
works, could it be thatRegisterWindowClass
is necessary for that to work ? Do you might have any idea as to why this event wont fire (while the other one works as expected) ?The text was updated successfully, but these errors were encountered: