Skip to content
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

macOS segfault when resizing #132

Open
kisasexypantera94 opened this issue Apr 21, 2022 · 2 comments
Open

macOS segfault when resizing #132

kisasexypantera94 opened this issue Apr 21, 2022 · 2 comments

Comments

@kisasexypantera94
Copy link

I am trying to capture window output on macOS:

#include <iostream>
#include <locale>

#include "ScreenCapture.h"

using namespace std;

int main()
{
  auto windowframgrabber =
      SL::Screen_Capture::CreateCaptureConfiguration(
          []()
          {
            try
            {
              auto windows = SL::Screen_Capture::GetWindows();
              return windows;
            }
            catch (const std::exception& e)
            {
              cout << "ERROR: " << e.what() << endl;
              return std::vector<SL::Screen_Capture::Window>{};
            }

          })
          ->onFrameChanged(
              [&](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Window& window) {
                // cout << "FrameChanged: " << window.Name << endl;
              })
          ->onNewFrame(
              [&](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Window& window) {
                // cout << "NewFrame: " << window.Name << endl;
              })
          ->onMouseChanged(
              [&](const SL::Screen_Capture::Image* img,
                  const SL::Screen_Capture::MousePoint& mousepoint) {
              })
          ->start_capturing();

  windowframgrabber->setFrameChangeInterval(std::chrono::milliseconds(100));  // 100 ms
  windowframgrabber->setMouseChangeInterval(std::chrono::milliseconds(100));  // 100 ms

  while (true)
  {

  }
}

However when I am dragging windows (three finger up gesture) it crashes with segfault.

I tried debugging but with lldb it immediately crashes even without dragging:

➜  build git:(master) ✗ sudo lldb screenshare_static
Password:
(lldb) target create "screenshare_static"
Current executable set to '/Users/a19531364/dev/screen_capture_lite/build/screenshare_static' (x86_64).
(lldb) run
error: shell expansion failed (reason: lldb-argdumper exited with error 1). consider launching with 'process launch'.
(lldb) process launch
Process 74255 launched: '/Users/a19531364/dev/screen_capture_lite/build/screenshare_static' (x86_64)
Process 74255 stopped
* thread #2, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00007fff203960f5 CoreFoundation`CFStringGetCString + 57
CoreFoundation`CFStringGetCString:
->  0x7fff203960f5 <+57>: movq   (%rbx), %rax
    0x7fff203960f8 <+60>: testq  %rax, %rax
    0x7fff203960fb <+63>: je     0x7fff20396128            ; <+108>
    0x7fff203960fd <+65>: leaq   0x5fcc4a84(%rip), %rcx    ; __CFConstantStringClassReferencePtr
Target 0: (screenshare_static) stopped.
(lldb) up
screenshare_static was compiled with optimization - stepping may behave oddly; variables may not be available.
frame #1: 0x000000010000d71c screenshare_static`SL::Screen_Capture::GetWindows() at GetWindows.cpp:55:13 [opt]
   52  	            uint32_t windowid=0;
   53  	            auto dict = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(windowList, i));
   54  	            auto cfwindowname = static_cast<CFStringRef>(CFDictionaryGetValue(dict, kCGWindowName));
-> 55  	            CFStringGetCString(cfwindowname, w.Name, sizeof(w.Name), kCFStringEncodingUTF8);
   56  	            w.Name[sizeof(w.Name)-1] = '\n';
   57
   58
(lldb)
@kisasexypantera94
Copy link
Author

It fixed the problem:

auto cfwindowname = static_cast<CFStringRef>(CFDictionaryGetValue(dict, kCGWindowName));
if (not cfwindowname)
{
  continue;
}

Could this be the solution?

@smasherprog
Copy link
Owner

If a window gets closed the application should handle this gracefully.
do a PR on it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants