smasherprog / screen_capture_lite

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

Error when CreateCaptureConfiguration lambda returns variable #103

Closed Phanty133 closed 3 years ago

Phanty133 commented 3 years ago

If I return SL::Screen_Capture::GetMonitors() directly in the CreateCaptureConfiguration lambda, everything works fine, but if I first set a variable to SL::Screen_Capture::GetMonitors() and I return it, I get Exiting Thread due to expected error in the console. The vector's size is 0 as well.

My code:

int main() {
    std::shared_ptr<SL::Screen_Capture::IScreenCaptureManager> frameGrabber = SL::Screen_Capture::CreateCaptureConfiguration([]() {
        std::vector<SL::Screen_Capture::Monitor> monitors = SL::Screen_Capture::GetMonitors();
        // std::cout << "Monitor count: " << monitors.size() << std::endl;
        return monitors;
        // return SL::Screen_Capture::GetMonitors();
    })->onNewFrame([&](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Monitor& monitor) {
        std::cout << SL::Screen_Capture::Width(img) << std::endl;
    })->start_capturing();

    frameGrabber->setFrameChangeInterval(std::chrono::milliseconds(100));

    std::this_thread::sleep_for(std::chrono::seconds(10));

    return 0;
}

I'm using x64 of release 17.0.3; Windows 10; MSVC C++14.

smasherprog commented 3 years ago

this is very strange. Ill check this example out to see if I can reproduce this.

smasherprog commented 3 years ago

So i did get around to testing this exact code with the same setup, x64 ms windows 10, etrc. I have no issues at all. Therefore, its going to be something more specific to your setup.

Id debug this by going into the getmonitors function and going step by step to see the differences.

smasherprog commented 3 years ago

If you want to set up a live share in visual studio we can debug this. Let me know

Phanty133 commented 3 years ago

I haven't had much time to look into the problem, but I managed to fix it? I switched to CMake with MSVC and just built the v17.0.3 source code together with my project. I used the CMakeLists.txt from the example, and it seems to work now. I still don't have the faintest clue of why it was bugging out in such a cursed way, but it works and I ain't tempting fate any further :).