smasherprog / screen_capture_lite

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

basic unity exsample #112

Open ludos1978 opened 2 years ago

ludos1978 commented 2 years ago

Hi, i've added a basic unity example in the fork https://github.com/ludos1978/screen_capture_lite . Also there is a extendedSample in scenes and in Scripts that are wip and not needed in the basic sample.

the dll or dylib needs to be added to the Example_Unity/UnityProject/Assets/Plugins folder so it works.

onMouseChanged and onNewFrame work as far as i can tell. But the onFrameChanged generates broken images. I assume thats an internal problem, also it has happened that i received a wrong size of buffer for the image size.

To cleanup i had to add a function. Unity closes the application fast and afaik only awaits the OnApplicationQuit function call. Garbage collection is not fast enougth i think. I do encounter problems when play/stopping the project in unity from time to time, but it's really hard to tell where these unity crashes come from. I assume it's because it may still execute the callback even if i set TerminateThreadsEvent true and Paused false in rare cases.

smasherprog commented 2 years ago

i see your not using dispose on the resources, this is likely whats causing the issues you are getting when trying to stop capturing. Mac has issues with inframechanged unfortuantly. I havent bug into that issue, but it looks like the images returned each frame from ios are slightly different from the previous. Maybe I need to add some jitter detection or dig into it more.

Dispose will block and wait until the capturing has completely stopped and all resources have been successfully cleaned up.

smasherprog commented 2 years ago

I think the stop function isnt necessary,. Give disposing the resources a shot and see if that fixes it.

ludos1978 commented 2 years ago

dispose seems to work equally well. i have checked in that change already, however i did not remove the stop functions from c & c# codes.

the problems with the images onFrameChanged appear to be a wrong width/height. width should be 2 - 3 times bigger. in most images.

smasherprog commented 2 years ago

Maybe its time for me to start up the good ol' mac thats collecting dust....

Ill see checking the mac stuff this weekend and look over the branch that you made.

Thanks for all the hard work. I saw that you were implementing your own c# library.

smasherprog commented 2 years ago

Fired up the good'ol mac, updated everything and everything seemed to work fine for my setup which is a simple, single monitor setup. I did try different scaling of my monitor and everything still seemed to work ok. I dont doubt that there are issues, but my mac debugging ability is limited so I cant see what needs to be fixed :( If you want to take a stab at fixing it, that would be awesome.

smasherprog commented 2 years ago

This was also not using unity. I dont use that either. I just did the simple demo of capturing monitors/windows

smasherprog commented 2 years ago

Also, on the topic of unity plugin. I was going through merging your code into the repo and was reviewing the code.

Since I dont use unity. The resource cleanup of OnApplicationQuit vs OnDestroy

Should OnDestory be used instead of OnApplicationQuit?

I am asking this because I generally dont know. I did google this and it seems to indicate that OnDestroy should be used. Is this correct?

ludos1978 commented 2 years ago

It does make sense to move the destroy code to that function if i think about it. However i would recommend testing the editor play/stopping again with OnDestroy multiple times. As the editor sometimes has issues with the cleanup of plugins which dont seem completely logical to me.

Am 06.09.2021 um 23:51 schrieb Scott @.***>:

Also, on the topic of unity plugin. I was going through merging your code into the repo and was reviewing the code.

Since I dont use unity. The resource cleanup of OnApplicationQuit vs OnDestroy

Should OnDestory be used instead of OnApplicationQuit?

I am asking this because I generally dont know. I did google this and it seems to indicate that OnDestroy should be used. Is this correct?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

ludos1978 commented 2 years ago

I just wanted to remind you that the samples in the repository https://github.com/ludos1978/screen_capture_lite should be working. if you wanna import them. you could leave out the ExtendedSample in Scripts and Sample as well as the built lib in Plugins and all the meta files with the same name as the files. but othervise it's about as small it gets.

smasherprog commented 2 years ago

Yeah sorry ive been busy. I did look at the example and was trying to use it locally. Ill get something up soon!