smasherprog / screen_capture_lite

cross platform screen/window capturing library
MIT License
638 stars 156 forks source link

How to compute image offsets for onFrameChanged? #96

Closed ababo closed 3 years ago

ababo commented 3 years ago

In v15.0.1 I was using Image.Bounds to get them. Now the image has become private, and there're no accessors to get those coordinates.

ababo commented 3 years ago

Another issue I have encountered on Mac when using 352b13f: it crashes when destructing:

* thread #5, stop reason = EXC_BAD_ACCESS (code=1, address=0x102a2ee8)
  * frame #0: 0x00007fff201b9d1d libobjc.A.dylib`objc_msgSend + 29
    frame #1: 0x0000000101d1b868 fortknox`SL::Screen_Capture::NSFrameProcessorImpl::~NSFrameProcessorImpl() + 72
    frame #2: 0x0000000101d1b653 fortknox`SL::Screen_Capture::DestroyNSFrameProcessorImpl(SL::Screen_Capture::NSFrameProcessorImpl*) + 19
    frame #3: 0x0000000101d1a863 fortknox`SL::Screen_Capture::NSFrameProcessor::~NSFrameProcessor() + 19
    frame #4: 0x0000000101d1ce9c fortknox`bool SL::Screen_Capture::TryCaptureMonitor<SL::Screen_Capture::NSFrameProcessor, std::__1::shared_ptr<SL::Screen_Capture::Thread_Data> >(std::__1::shared_ptr<SL::Screen_Capture::Thread_Data> const&, SL::Screen_Capture::Monitor&) + 1068
    frame #5: 0x0000000101d1ca6d fortknox`SL::Screen_Capture::RunCaptureMonitor(std::__1::shared_ptr<SL::Screen_Capture::Thread_Data>, SL::Screen_Capture::Monitor) + 13
    frame #6: 0x0000000101d19ec7 fortknox`void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)(std::__1::shared_ptr<SL::Screen_Capture::Thread_Data>, SL::Screen_Capture::Monitor), std::__1::shared_ptr<SL::Screen_Capture::Thread_Data>, SL::Screen_Capture::Monitor> >(void*) + 135
    frame #7: 0x00007fff2031d950 libsystem_pthread.dylib`_pthread_start + 224
    frame #8: 0x00007fff2031947b libsystem_pthread.dylib`thread_start + 15
ababo commented 3 years ago

This diff fixes the issue:

diff --git a/src/ios/NSFrameProcessor.mm b/src/ios/NSFrameProcessor.mm
index f1e462a..4f7d945 100644
--- a/src/ios/NSFrameProcessor.mm
+++ b/src/ios/NSFrameProcessor.mm
@@ -113,12 +113,12 @@ void SetFrameInterval(FrameProcessor* f, int ms){
             ~NSFrameProcessorImpl(){
                 if(ptr) {
                     [ptr Stop];
-                    [ptr release];
                     auto r = CFGetRetainCount(ptr);
                     while(r!=1){
                         r = CFGetRetainCount(ptr);
                         std::this_thread::sleep_for(std::chrono::milliseconds(50));
                     }
+                    [ptr release];
                     ptr = nullptr;
                 }
             }
smasherprog commented 3 years ago

do a PR please so i can merge it into master

smasherprog commented 3 years ago

PR was merged in closing this ticket. Thanks for the PR!! 👍