From 9baed3bf7e28d1a92dc3d88d62526a95e83a5aa2 Mon Sep 17 00:00:00 2001 From: scott Date: Wed, 9 Aug 2017 05:57:55 -0700 Subject: [PATCH] Added check in linux for window change detection --- Example/Screen_Capture_Example.cpp | 14 ++++++++------ src/linux/X11FrameProcessor.cpp | 8 +++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Example/Screen_Capture_Example.cpp b/Example/Screen_Capture_Example.cpp index b00793c1..b8d6fcde 100644 --- a/Example/Screen_Capture_Example.cpp +++ b/Example/Screen_Capture_Example.cpp @@ -105,18 +105,20 @@ void createwindowgrabber() auto s = std::to_string(r) + std::string("WINDIF_") + std::string(".jpg"); auto size = RowStride(img) * Height(img); - /* auto imgbuffer(std::make_unique(size)); + /* auto imgbuffer(std::make_unique(size)); ExtractAndConvertToRGBA(img, imgbuffer.get(), size); - tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char*)imgbuffer.get());*/ + tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char*)imgbuffer.get()); + */ })->onNewFrame([&](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Window& window) { auto r = realcounter.fetch_add(1); auto s = std::to_string(r) + std::string("WINNEW_") + std::string(".jpg"); - - auto size = RowStride(img) * Height(img);/* - auto imgbuffer(std::make_unique(size)); + auto size = RowStride(img) * Height(img); + + /* auto imgbuffer(std::make_unique(size)); ExtractAndConvertToRGBA(img, imgbuffer.get(), size); - tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char*)imgbuffer.get());*/ + tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char*)imgbuffer.get()); + */ if (std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - onNewFramestart).count() >= 1000) { std::cout << "onNewFrame fps" << onNewFramecounter << std::endl; onNewFramecounter = 0; diff --git a/src/linux/X11FrameProcessor.cpp b/src/linux/X11FrameProcessor.cpp index 120724ba..e1b6aa0c 100644 --- a/src/linux/X11FrameProcessor.cpp +++ b/src/linux/X11FrameProcessor.cpp @@ -123,7 +123,13 @@ namespace Screen_Capture ret.left = ret.top = 0; ret.right = selectedwindow.Size.x; ret.bottom = selectedwindow.Size.y; - + XWindowAttributes wndattr; + if(XGetWindowAttributes(SelectedDisplay, SelectedWindow, &wndattr) ==0){ + return DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED;//window might not be valid any more + } + if(wndattr.width != ret.right || wndattr.height != ret.bottom){ + return DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED;//window size changed. This will rebuild everything + } if(!XShmGetImage(SelectedDisplay, selectedwindow.Handle, Image,